fn determine_format_w_datetimefield(
    mut toks: VecDeque<TimeStrToken>,
) -> Result<Option<TimePartFormat>, String> {
    use DateTimeField::*;
    use TimePartFormat::*;
    use TimeStrToken::*;

    trim_and_return_sign(&mut toks);

    if let Some(Num(_, _)) = toks.front() {
        toks.pop_front();
    }

    match toks.pop_front() {
        // Implies {?}{?}{?}, ambiguous case.
        None | Some(Delim) => Ok(None),
        Some(Dot) => {
            match toks.front() {
                Some(Num(_, _)) | Some(Nanos(_)) => {
                    toks.pop_front();
                }
                _ => {}
            }
            match toks.pop_front() {
                // Implies {Num.NumTimeUnit}
                Some(TimeUnit(f)) => Ok(Some(PostgreSql(f))),
                // Implies {?}{?}{?}, ambiguous case.
                _ => Ok(None),
            }
        }
        // Implies {Y-...}{}{}
        Some(Dash) => Ok(Some(SqlStandard(Year))),
        // Implies {}{}{?:...}
        Some(Colon) => {
            if let Some(Num(_, _)) = toks.front() {
                toks.pop_front();
            }
            match toks.pop_front() {
                // Implies {H:M:?...}
                Some(Colon) | Some(Delim) | None => Ok(Some(SqlStandard(Hour))),
                // Implies {M:S.NS}
                Some(Dot) => Ok(Some(SqlStandard(Minute))),
                _ => Err("Cannot determine format of all parts".into()),
            }
        }
        // Implies {Num}?{TimeUnit}
        Some(TimeUnit(f)) => Ok(Some(PostgreSql(f))),
        Some(DateTimeUnit(DateTimeUnits::Hour)) => Ok(Some(PostgreSql(Hour))),
        Some(DateTimeUnit(DateTimeUnits::Minute)) => Ok(Some(PostgreSql(Minute))),
        Some(DateTimeUnit(DateTimeUnits::Second)) => Ok(Some(PostgreSql(Second))),
        Some(DateTimeUnit(_)) => Ok(None),
        _ => Err("Cannot determine format of all parts".into()),
    }
}
/// Determines the format of the interval part (uses None to identify an
/// indeterminant/ambiguous format). This is necessary because the interval
/// string format is not LL(1); we instead parse as few tokens as possible to
/// generate the string's semantics.
///
/// Note that `toks` should _not_ contain space
Determines the format of the interval part (uses None to identify an
indeterminant/ambiguous format). This is necessary because the interval
string format is not LL(1); we instead parse as few tokens as possible to
generate the string's semantics.

Note that `toks` should _not_ contain space
Determines the format of the interval part ( uses None to identify an indeterminant / ambiguous format ) . This is necessary because the interval string format is not LL ( 1 ) ; we instead parse as few tokens as possible to generate the string ' s semantics . Note that ` toks ` should _not_ contain space
fn determine_format_w_datetimefield(
    mut toks: VecDeque<TimeStrToken>,
) -> Result<Option<TimePartFormat>, String> {
    use DateTimeField::*;
    use TimePartFormat::*;
    use TimeStrToken::*;
    trim_and_return_sign(&mut toks);
    if let Some(Num(_, _)) = toks.front() {
        toks.pop_front();
    }
    match toks.pop_front() {
        // Implies {?}{?}{?}, ambiguous case.
        None | Some(Delim) => Ok(None),
        Some(Dot) => {
            match toks.front() {
                Some(Num(_, _)) | Some(Nanos(_)) => {
                    toks.pop_front();
                }
                _ => {}
            }
            match toks.pop_front() {
                // Implies {Num.NumTimeUnit}
                Some(TimeUnit(f)) => Ok(Some(PostgreSql(f))),
                // Implies {?}{?}{?}, ambiguous case.
                _ => Ok(None),
            }
        }
        // Implies {Y-...}{}{}
        Some(Dash) => Ok(Some(SqlStandard(Year))),
        // Implies {}{}{?:...}
        Some(Colon) => {
            if let Some(Num(_, _)) = toks.front() {
                toks.pop_front();
            }
            match toks.pop_front() {
                // Implies {H:M:?...}
                Some(Colon) | Some(Delim) | None => Ok(Some(SqlStandard(Hour))),
                // Implies {M:S.NS}
                Some(Dot) => Ok(Some(SqlStandard(Minute))),
                _ => Err("Cannot determine format of all parts".into()),
            }
        }
        // Implies {Num}?{TimeUnit}
        Some(TimeUnit(f)) => Ok(Some(PostgreSql(f))),
        Some(DateTimeUnit(DateTimeUnits::Hour)) => Ok(Some(PostgreSql(Hour))),
        Some(DateTimeUnit(DateTimeUnits::Minute)) => Ok(Some(PostgreSql(Minute))),
        Some(DateTimeUnit(DateTimeUnits::Second)) => Ok(Some(PostgreSql(Second))),
        Some(DateTimeUnit(_)) => Ok(None),
        _ => Err("Cannot determine format of all parts".into()),
    }
}
fn determine_format_w_datetimefield ( mut toks : VecDeque < TimeStrToken > , ) -> Result < Option < TimePartFormat > , String > { use DateTimeField :: * ; use TimePartFormat :: * ; use TimeStrToken :: * ; trim_and_return_sign ( & mut toks ) ; if let Some ( Num ( _ , _ ) ) = toks . front ( ) { toks . pop_front ( ) ; } match toks . pop_front ( ) { // Implies {?}{?}{?}, ambiguous case. None | Some ( Delim ) => Ok ( None ) , Some ( Dot ) => { match toks . front ( ) { Some ( Num ( _ , _ ) ) | Some ( Nanos ( _ ) ) => { toks . pop_front ( ) ; } _ => { } } match toks . pop_front ( ) { // Implies {Num.NumTimeUnit} Some ( TimeUnit ( f ) ) => Ok ( Some ( PostgreSql ( f ) ) ) , // Implies {?}{?}{?}, ambiguous case. _ => Ok ( None ) , } } // Implies {Y-...}{}{} Some ( Dash ) => Ok ( Some ( SqlStandard ( Year ) ) ) , // Implies {}{}{?:...} Some ( Colon ) => { if let Some ( Num ( _ , _ ) ) = toks . front ( ) { toks . pop_front ( ) ; } match toks . pop_front ( ) { // Implies {H:M:?...} Some ( Colon ) | Some ( Delim ) | None => Ok ( Some ( SqlStandard ( Hour ) ) ) , // Implies {M:S.NS} Some ( Dot ) => Ok ( Some ( SqlStandard ( Minute ) ) ) , _ => Err ( " " . into ( ) ) , } } // Implies {Num}?{TimeUnit} Some ( TimeUnit ( f ) ) => Ok ( Some ( PostgreSql ( f ) ) ) , Some ( DateTimeUnit ( DateTimeUnits :: Hour ) ) => Ok ( Some ( PostgreSql ( Hour ) ) ) , Some ( DateTimeUnit ( DateTimeUnits :: Minute ) ) => Ok ( Some ( PostgreSql ( Minute ) ) ) , Some ( DateTimeUnit ( DateTimeUnits :: Second ) ) => Ok ( Some ( PostgreSql ( Second ) ) ) , Some ( DateTimeUnit ( _ ) ) => Ok ( None ) , _ => Err ( " " . into ( ) ) , } }
Determines the format of the interval part (uses None to identify an
indeterminant/ambiguous format).
Determines the format of the interval part ( uses None to identify an indeterminant / ambiguous format ) .
toks
VecDeque<TimeStrToken>
toks
VecDeque<TimeStrToken>