fn from_str(s: &str) -> Result<DateTuple, Self::Err> {
        lazy_static! {
            static ref VALID_FORMAT: Regex = Regex::new(r"^\d{4}-\d{2}-\d{2}$").unwrap();
            static ref LEGACY_FORMAT: Regex = Regex::new(r"^\d{8}$").unwrap();
        }

        if VALID_FORMAT.is_match(s) {
            match DateTuple::new(
                u16::from_str(&s[0..4]).unwrap(),
                u8::from_str(&s[5..7]).unwrap(),
                u8::from_str(&s[8..10]).unwrap(),
            ) {
                Ok(d) => Ok(d),
                Err(e) => Err(format!("Invalid date passed to from_str: {}", e)),
            }
        } else if LEGACY_FORMAT.is_match(s) {
            let (s1, s2) = s.split_at(4);
            let (s2, s3) = s2.split_at(2);
            match DateTuple::new(
                u16::from_str(s1).unwrap(),
                u8::from_str(s2).unwrap(),
                u8::from_str(s3).unwrap(),
            ) {
                Ok(d) => Ok(d),
                Err(e) => Err(format!("Invalid date passed to from_str: {}", e)),
            }
        } else {
            Err(format!("Invalid str formatting of DateTuple: {}\nExpects a string formatted like 2018-11-02.", s))
        }
    }
/// Expects a string formatted like 2018-11-02.
///
/// Also accepts the legacy crate format of 20181102.
Expects a string formatted like 2018-11-02.
Also accepts the legacy crate format of 20181102.
Expects a string formatted like 2018 - 11 - 02 . Also accepts the legacy crate format of 20181102 .
fn from_str(s: &str) -> Result<DateTuple, Self::Err> {
        lazy_static! {
            static ref VALID_FORMAT: Regex = Regex::new(r"^\d{4}-\d{2}-\d{2}$").unwrap();
            static ref LEGACY_FORMAT: Regex = Regex::new(r"^\d{8}$").unwrap();
        }
        if VALID_FORMAT.is_match(s) {
            match DateTuple::new(
                u16::from_str(&s[0..4]).unwrap(),
                u8::from_str(&s[5..7]).unwrap(),
                u8::from_str(&s[8..10]).unwrap(),
            ) {
                Ok(d) => Ok(d),
                Err(e) => Err(format!("Invalid date passed to from_str: {}", e)),
            }
        } else if LEGACY_FORMAT.is_match(s) {
            let (s1, s2) = s.split_at(4);
            let (s2, s3) = s2.split_at(2);
            match DateTuple::new(
                u16::from_str(s1).unwrap(),
                u8::from_str(s2).unwrap(),
                u8::from_str(s3).unwrap(),
            ) {
                Ok(d) => Ok(d),
                Err(e) => Err(format!("Invalid date passed to from_str: {}", e)),
            }
        } else {
            Err(format!("Invalid str formatting of DateTuple: {}\nExpects a string formatted like 2018-11-02.", s))
        }
    }
fn from_str ( s : & str ) -> Result < DateTuple , Self :: Err > { lazy_static ! { static ref VALID_FORMAT Regex Regex new ( r"^\d{4}-\d{2}-\d{2}$" ) unwrap ( ) static ref LEGACY_FORMAT Regex Regex new ( r"^\d{8}$" ) unwrap ( ) } if VALID_FORMAT . is_match ( s ) { match DateTuple :: new ( u16 :: from_str ( & s [ 0 .. 4 ] ) . unwrap ( ) , u8 :: from_str ( & s [ 5 .. 7 ] ) . unwrap ( ) , u8 :: from_str ( & s [ 8 .. 10 ] ) . unwrap ( ) , ) { Ok ( d ) => Ok ( d ) , Err ( e ) => Err ( format ! ( " " e ) ) , } } else if LEGACY_FORMAT . is_match ( s ) { let ( s1 , s2 ) = s . split_at ( 4 ) ; let ( s2 , s3 ) = s2 . split_at ( 2 ) ; match DateTuple :: new ( u16 :: from_str ( s1 ) . unwrap ( ) , u8 :: from_str ( s2 ) . unwrap ( ) , u8 :: from_str ( s3 ) . unwrap ( ) , ) { Ok ( d ) => Ok ( d ) , Err ( e ) => Err ( format ! ( " " e ) ) , } } else { Err ( format ! ( " \n " s ) ) } }
Expects a string formatted like 2018-11-02.
Expects a string formatted like 2018 - 11 - 02 .
s
&str
s
&str