fn parse_game(game_json: &GameResponse) -> Option<Game> {
    let home_team = &game_json.teams.home.abbreviation;
    let away_team = &game_json.teams.away.abbreviation;

    let home_score = &game_json.scores[home_team];
    let away_score = &game_json.scores[away_team];

    let all_goals = &game_json.goals;

    let special = match all_goals.last() {
        None => "",
        Some(last_goal) => {
            let period = &last_goal.period;
            match period.as_str() {
                "1" | "2" | "3" => "",
                "OT" => "ot",
                "SO" => "so",
                // The default case is "ot" because the only ones
                // with chars should be OT and SO and this matches
                // Any digit larger than 3.
                // If other periods occur, new arms should be added
                _ => "ot",
            }
        }
    };

    let goals: &Vec<GoalResponse> = &game_json.goals;

    let goals = goals
        .into_iter()
        .map(|goal| {
            let minute = match goal.period.as_str() {
                "SO" => SHOOTOUT_MINUTE,
                _ => format_minute(goal.min.unwrap(), &goal.period),
            };

            let scorer = extract_scorer_name(&goal.scorer.player);

            return Goal {
                scorer: scorer,
                minute: minute,
                team: goal.team.replace("\"", ""),
                special: is_special(goal),
            };
        })
        .collect::<Vec<Goal>>();

    let score = format!("{}-{}", home_score, away_score);
    let game = Game {
        home: String::from(home_team),
        away: String::from(away_team),
        score: score.to_owned(),
        goals: goals,
        status: String::from(&game_json.status.state),
        special: String::from(special),
        playoff_series: game_json.current_stats.playoff_series.clone(),
    };

    Some(game)
}
/// Transforms a JSON structure of an individual game into a Game
Transforms a JSON structure of an individual game into a Game
Transforms a JSON structure of an individual game into a Game
fn parse_game(game_json: &GameResponse) -> Option<Game> {
    let home_team = &game_json.teams.home.abbreviation;
    let away_team = &game_json.teams.away.abbreviation;
    let home_score = &game_json.scores[home_team];
    let away_score = &game_json.scores[away_team];
    let all_goals = &game_json.goals;
    let special = match all_goals.last() {
        None => "",
        Some(last_goal) => {
            let period = &last_goal.period;
            match period.as_str() {
                "1" | "2" | "3" => "",
                "OT" => "ot",
                "SO" => "so",
                // The default case is "ot" because the only ones
                // with chars should be OT and SO and this matches
                // Any digit larger than 3.
                // If other periods occur, new arms should be added
                _ => "ot",
            }
        }
    };
    let goals: &Vec<GoalResponse> = &game_json.goals;
    let goals = goals
        .into_iter()
        .map(|goal| {
            let minute = match goal.period.as_str() {
                "SO" => SHOOTOUT_MINUTE,
                _ => format_minute(goal.min.unwrap(), &goal.period),
            };
            let scorer = extract_scorer_name(&goal.scorer.player);
            return Goal {
                scorer: scorer,
                minute: minute,
                team: goal.team.replace("\"", ""),
                special: is_special(goal),
            };
        })
        .collect::<Vec<Goal>>();
    let score = format!("{}-{}", home_score, away_score);
    let game = Game {
        home: String::from(home_team),
        away: String::from(away_team),
        score: score.to_owned(),
        goals: goals,
        status: String::from(&game_json.status.state),
        special: String::from(special),
        playoff_series: game_json.current_stats.playoff_series.clone(),
    };
    Some(game)
}
fn parse_game ( game_json : & GameResponse ) -> Option < Game > { let home_team = & game_json . teams . home . abbreviation ; let away_team = & game_json . teams . away . abbreviation ; let home_score = & game_json . scores [ home_team ] ; let away_score = & game_json . scores [ away_team ] ; let all_goals = & game_json . goals ; let special = match all_goals . last ( ) { None => " " , Some ( last_goal ) => { let period = & last_goal . period ; match period . as_str ( ) { " " | " " | " " => " " , " " => " " , " " => " " , // The default case is "ot" because the only ones // with chars should be OT and SO and this matches // Any digit larger than 3. // If other periods occur, new arms should be added _ => " " , } } } ; let goals : & Vec < GoalResponse > = & game_json . goals ; let goals = goals . into_iter ( ) . map ( | goal | { let minute = match goal . period . as_str ( ) { " " => SHOOTOUT_MINUTE , _ => format_minute ( goal . min . unwrap ( ) , & goal . period ) , } ; let scorer = extract_scorer_name ( & goal . scorer . player ) ; return Goal { scorer : scorer , minute : minute , team : goal . team . replace ( " \" " , " " ) , special : is_special ( goal ) , } ; } ) . collect :: < Vec < Goal > > ( ) ; let score = format ! ( " " home_score away_score ) ; let game = Game { home : String :: from ( home_team ) , away : String :: from ( away_team ) , score : score . to_owned ( ) , goals : goals , status : String :: from ( & game_json . status . state ) , special : String :: from ( special ) , playoff_series : game_json . current_stats . playoff_series . clone ( ) , } ; Some ( game ) }
Transforms a JSON structure of an individual game into a Game
Transforms a JSON structure of an individual game into a Game
game_json
&GameResponse
game_json
&GameResponse