fn parse_year(advisory_id: &str) -> Result<u32, Error> {
    let mut parts = advisory_id.split('-');
    parts.next().unwrap();

    let year = match parts.next().unwrap().parse::<u32>() {
        Ok(n) => match n {
            YEAR_MIN..=YEAR_MAX => n,
            _ => fail!(
                ErrorKind::Parse,
                "out-of-range year in advisory ID: {}",
                advisory_id
            ),
        },
        _ => fail!(
            ErrorKind::Parse,
            "malformed year in advisory ID: {}",
            advisory_id
        ),
    };

    if let Some(num) = parts.next() {
        if num.parse::<u32>().is_err() {
            fail!(ErrorKind::Parse, "malformed advisory ID: {}", advisory_id);
        }
    } else {
        fail!(ErrorKind::Parse, "incomplete advisory ID: {}", advisory_id);
    }

    if parts.next().is_some() {
        fail!(ErrorKind::Parse, "malformed advisory ID: {}", advisory_id);
    }

    Ok(year)
}
/// Parse the year from an advisory identifier
Parse the year from an advisory identifier
Parse the year from an advisory identifier
fn parse_year(advisory_id: &str) -> Result<u32, Error> {
    let mut parts = advisory_id.split('-');
    parts.next().unwrap();
    let year = match parts.next().unwrap().parse::<u32>() {
        Ok(n) => match n {
            YEAR_MIN..=YEAR_MAX => n,
            _ => fail!(
                ErrorKind::Parse,
                "out-of-range year in advisory ID: {}",
                advisory_id
            ),
        },
        _ => fail!(
            ErrorKind::Parse,
            "malformed year in advisory ID: {}",
            advisory_id
        ),
    };
    if let Some(num) = parts.next() {
        if num.parse::<u32>().is_err() {
            fail!(ErrorKind::Parse, "malformed advisory ID: {}", advisory_id);
        }
    } else {
        fail!(ErrorKind::Parse, "incomplete advisory ID: {}", advisory_id);
    }
    if parts.next().is_some() {
        fail!(ErrorKind::Parse, "malformed advisory ID: {}", advisory_id);
    }
    Ok(year)
}
fn parse_year ( advisory_id : & str ) -> Result < u32 , Error > { let mut parts = advisory_id . split ( '-' ) ; parts . next ( ) . unwrap ( ) ; let year = match parts . next ( ) . unwrap ( ) . parse :: < u32 > ( ) { Ok ( n ) => match n { YEAR_MIN ..= YEAR_MAX => n , _ => fail ! ( ErrorKind Parse " " advisory_id ) , } , _ => fail ! ( ErrorKind Parse " " advisory_id ) , } ; if let Some ( num ) = parts . next ( ) { if num . parse :: < u32 > ( ) . is_err ( ) { fail ! ( ErrorKind Parse " " advisory_id ) ; } } else { fail ! ( ErrorKind Parse " " advisory_id ) ; } if parts . next ( ) . is_some ( ) { fail ! ( ErrorKind Parse " " advisory_id ) ; } Ok ( year ) }
Parse the year from an advisory identifier
Parse the year from an advisory identifier
advisory_id
&str
advisory_id
&str