/// Helper function to build structured innings information of a match
///
/// # Arguments
///
/// * `div` - Refers to the div element in the HTML page containing the innings information
/// * `scorecard` - Vector of all innings information
Helper function to build structured innings information of a match
Helper function to build structured innings information of a match
fn populate_innings_info(div: &ElementRef, scorecard: &mut Vec<MatchInningsInfo>) {
    // These unwraps will never panic
    let sel_scrd_items = Selector::parse("div.cb-scrd-itms").unwrap();
    let sel_div = Selector::parse("div").unwrap();
    let mut match_inngs_info = MatchInningsInfo::default();
    for inner_div in div.select(&sel_scrd_items) {
        // Check for batsman or bowler scorcard info
        let num_child_div = inner_div.select(&sel_div).count();
        if num_child_div == 7 {
            // This is for batsman info
            let mut bat_info = BatsmanInfo::default();
            let mut divs = inner_div.select(&sel_div);
            if let Some(bat_name_link) = divs.next() {
                bat_info.name = bat_name_link
                    .text()
                    .collect::<Vec<&str>>()
                    .concat()
                    .trim()
                    .to_string();
            }
            if let Some(div) = divs.next() {
                bat_info.status = div
                    .text()
                    .collect::<Vec<&str>>()
                    .concat()
                    .trim()
                    .to_string()
            }
            if let Some(div) = divs.next() {
                bat_info.runs = div.inner_html().trim().to_string();
            }
            if let Some(div) = divs.next() {
                bat_info.balls = div.inner_html().trim().to_string();
            }
            if let Some(div) = divs.next() {
                bat_info.fours = div.inner_html().trim().to_string();
            }
            if let Some(div) = divs.next() {
                bat_info.sixes = div.inner_html().trim().to_string();
            }
            if let Some(div) = divs.next() {
                bat_info.strike_rate = div.inner_html().trim().to_string();
            }
            match_inngs_info.batsman_details.push(bat_info);
        } else if num_child_div == 8 {
            // This is for bowler info
            let mut bowl_info = BowlerInfo::default();
            let mut divs = inner_div.select(&sel_div);
            if let Some(bowl_name_link) = divs.next() {
                bowl_info.name = bowl_name_link
                    .text()
                    .collect::<Vec<&str>>()
                    .concat()
                    .trim()
                    .to_string();
            }
            if let Some(div) = divs.next() {
                bowl_info.overs = div.inner_html().trim().to_string();
            }
            if let Some(div) = divs.next() {
                bowl_info.maidens = div.inner_html().trim().to_string();
            }
            if let Some(div) = divs.next() {
                bowl_info.runs = div.inner_html().trim().to_string();
            }
            if let Some(div) = divs.next() {
                bowl_info.wickets = div.inner_html().trim().to_string();
            }
            if let Some(div) = divs.next() {
                bowl_info.no_balls = div.inner_html().trim().to_string();
            }
            if let Some(div) = divs.next() {
                bowl_info.wides = div.inner_html().trim().to_string();
            }
            if let Some(div) = divs.next() {
                bowl_info.economy = div.inner_html().trim().to_string();
            }
            match_inngs_info.bowler_details.push(bowl_info);
        }
    }
    scorecard.push(match_inngs_info);
}
fn populate_innings_info ( div : & ElementRef , scorecard : & mut Vec < MatchInningsInfo > ) { // These unwraps will never panic let sel_scrd_items = Selector :: parse ( " " ) . unwrap ( ) ; let sel_div = Selector :: parse ( " " ) . unwrap ( ) ; let mut match_inngs_info = MatchInningsInfo :: default ( ) ; for inner_div in div . select ( & sel_scrd_items ) { // Check for batsman or bowler scorcard info let num_child_div = inner_div . select ( & sel_div ) . count ( ) ; if num_child_div == 7 { // This is for batsman info let mut bat_info = BatsmanInfo :: default ( ) ; let mut divs = inner_div . select ( & sel_div ) ; if let Some ( bat_name_link ) = divs . next ( ) { bat_info . name = bat_name_link . text ( ) . collect :: < Vec < & str > > ( ) . concat ( ) . trim ( ) . to_string ( ) ; } if let Some ( div ) = divs . next ( ) { bat_info . status = div . text ( ) . collect :: < Vec < & str > > ( ) . concat ( ) . trim ( ) . to_string ( ) } if let Some ( div ) = divs . next ( ) { bat_info . runs = div . inner_html ( ) . trim ( ) . to_string ( ) ; } if let Some ( div ) = divs . next ( ) { bat_info . balls = div . inner_html ( ) . trim ( ) . to_string ( ) ; } if let Some ( div ) = divs . next ( ) { bat_info . fours = div . inner_html ( ) . trim ( ) . to_string ( ) ; } if let Some ( div ) = divs . next ( ) { bat_info . sixes = div . inner_html ( ) . trim ( ) . to_string ( ) ; } if let Some ( div ) = divs . next ( ) { bat_info . strike_rate = div . inner_html ( ) . trim ( ) . to_string ( ) ; } match_inngs_info . batsman_details . push ( bat_info ) ; } else if num_child_div == 8 { // This is for bowler info let mut bowl_info = BowlerInfo :: default ( ) ; let mut divs = inner_div . select ( & sel_div ) ; if let Some ( bowl_name_link ) = divs . next ( ) { bowl_info . name = bowl_name_link . text ( ) . collect :: < Vec < & str > > ( ) . concat ( ) . trim ( ) . to_string ( ) ; } if let Some ( div ) = divs . next ( ) { bowl_info . overs = div . inner_html ( ) . trim ( ) . to_string ( ) ; } if let Some ( div ) = divs . next ( ) { bowl_info . maidens = div . inner_html ( ) . trim ( ) . to_string ( ) ; } if let Some ( div ) = divs . next ( ) { bowl_info . runs = div . inner_html ( ) . trim ( ) . to_string ( ) ; } if let Some ( div ) = divs . next ( ) { bowl_info . wickets = div . inner_html ( ) . trim ( ) . to_string ( ) ; } if let Some ( div ) = divs . next ( ) { bowl_info . no_balls = div . inner_html ( ) . trim ( ) . to_string ( ) ; } if let Some ( div ) = divs . next ( ) { bowl_info . wides = div . inner_html ( ) . trim ( ) . to_string ( ) ; } if let Some ( div ) = divs . next ( ) { bowl_info . economy = div . inner_html ( ) . trim ( ) . to_string ( ) ; } match_inngs_info . bowler_details . push ( bowl_info ) ; } } scorecard . push ( match_inngs_info ) ; }
Helper function to build structured innings information of a match
Helper function to build structured innings information of a match
div
&ElementRef
scorecard
&mut Vec<MatchInningsInfo>