pub(crate) fn try_consume_exact_digits<T: FromStr>(
    s: &mut &str,
    num_digits: usize,
    padding: Padding,
) -> Option<T> {
    let pad_size = match padding {
        Padding::Space => consume_padding(s, padding, num_digits - 1),
        _ => 0,
    };

    if padding == Padding::None {
        try_consume_digits(s, 1, num_digits - pad_size)
    } else {
        // Ensure all the necessary characters are ASCII digits.
        if !s
            .chars()
            .take(num_digits - pad_size)
            .all(|c| c.is_ascii_digit())
        {
            return None;
        }

        // Ensure the string is long enough to perform the slicing.
        if (num_digits - pad_size) > s.len() {
            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[..(num_digits - pad_size)];
        *s = &s[(num_digits - pad_size)..];
        digits.parse::<T>().ok()
    }
}
/// Attempt to consume an exact number of digits.
Attempt to consume an exact number of digits.
Attempt to consume an exact number of digits .
pub(crate) fn try_consume_exact_digits<T: FromStr>(
    s: &mut &str,
    num_digits: usize,
    padding: Padding,
) -> Option<T> {
    let pad_size = match padding {
        Padding::Space => consume_padding(s, padding, num_digits - 1),
        _ => 0,
    };
    if padding == Padding::None {
        try_consume_digits(s, 1, num_digits - pad_size)
    } else {
        // Ensure all the necessary characters are ASCII digits.
        if !s
            .chars()
            .take(num_digits - pad_size)
            .all(|c| c.is_ascii_digit())
        {
            return None;
        }
        // Ensure the string is long enough to perform the slicing.
        if (num_digits - pad_size) > s.len() {
            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[..(num_digits - pad_size)];
        *s = &s[(num_digits - pad_size)..];
        digits.parse::<T>().ok()
    }
}
pub ( crate ) fn try_consume_exact_digits < T : FromStr > ( s : & mut & str , num_digits : usize , padding : Padding , ) -> Option < T > { let pad_size = match padding { Padding :: Space => consume_padding ( s , padding , num_digits - 1 ) , _ => 0 , } ; if padding == Padding :: None { try_consume_digits ( s , 1 , num_digits - pad_size ) } else { // Ensure all the necessary characters are ASCII digits. if ! s . chars ( ) . take ( num_digits - pad_size ) . all ( | c | c . is_ascii_digit ( ) ) { return None ; } // Ensure the string is long enough to perform the slicing. if ( num_digits - pad_size ) > s . len ( ) { 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 [ .. ( num_digits - pad_size ) ] ; * s = & s [ ( num_digits - pad_size ) .. ] ; digits . parse :: < T > ( ) . ok ( ) } }
Attempt to consume an exact number of digits.
Attempt to consume an exact number of digits .
s
&mut &str
num_digits
usize
padding
Padding
s
&mut &str
num_digits
usize
padding
Padding