pub(crate) fn try_consume_digits<T: FromStr>(
    s: &mut &str,
    min_digits: usize,
    max_digits: usize,
) -> Option<T> {
    // Determine how many digits the string starts with, up to the upper limit
    // of the range.
    let len = s
        .chars()
        .take(max_digits)
        .take_while(char::is_ascii_digit)
        .count();

    // We don't have enough digits.
    if len < min_digits {
        return None;
    }

    // Because we're only dealing with ASCII digits here, we know that the
    // length is equal to the number of bytes, as ASCII values are always one
    // byte in Unicode.
    let digits = &s[..len];
    *s = &s[len..];
    digits.parse::<T>().ok()
}
/// Attempt to consume a number of digits. Consumes the maximum amount possible
/// within the range provided.
Attempt to consume a number of digits. Consumes the maximum amount possible
within the range provided.
Attempt to consume a number of digits . Consumes the maximum amount possible within the range provided .
pub(crate) fn try_consume_digits<T: FromStr>(
    s: &mut &str,
    min_digits: usize,
    max_digits: usize,
) -> Option<T> {
    // Determine how many digits the string starts with, up to the upper limit
    // of the range.
    let len = s
        .chars()
        .take(max_digits)
        .take_while(char::is_ascii_digit)
        .count();
    // We don't have enough digits.
    if len < min_digits {
        return None;
    }
    // Because we're only dealing with ASCII digits here, we know that the
    // length is equal to the number of bytes, as ASCII values are always one
    // byte in Unicode.
    let digits = &s[..len];
    *s = &s[len..];
    digits.parse::<T>().ok()
}
pub ( crate ) fn try_consume_digits < T : FromStr > ( s : & mut & str , min_digits : usize , max_digits : usize , ) -> Option < T > { // Determine how many digits the string starts with, up to the upper limit // of the range. let len = s . chars ( ) . take ( max_digits ) . take_while ( char :: is_ascii_digit ) . count ( ) ; // We don't have enough digits. if len < min_digits { return None ; } // Because we're only dealing with ASCII digits here, we know that the // length is equal to the number of bytes, as ASCII values are always one // byte in Unicode. let digits = & s [ .. len ] ; * s = & s [ len .. ] ; digits . parse :: < T > ( ) . ok ( ) }
Attempt to consume a number of digits.
Attempt to consume a number of digits .
s
&mut &str
min_digits
usize
max_digits
usize
s
&mut &str
min_digits
usize
max_digits
usize