fn parse_exp<'a>(integral: &'a [u8], fractional: &'a [u8], rest: &'a [u8]) -> ParseResult<'a> {
    let (sign, rest) = match rest.first() {
        Some(&b'-') => (Sign::Negative, &rest[1..]),
        Some(&b'+') => (Sign::Positive, &rest[1..]),
        _ => (Sign::Positive, rest),
    };
    let (mut number, trailing) = eat_digits(rest);
    if !trailing.is_empty() {
        return Invalid; // Trailing junk after exponent
    }
    if number.is_empty() {
        return Invalid; // Empty exponent
    }
    // At this point, we certainly have a valid string of digits. It may be too long to put into
    // an `i64`, but if it's that huge, the input is certainly zero or infinity. Since each zero
    // in the decimal digits only adjusts the exponent by +/- 1, at exp = 10^18 the input would
    // have to be 17 exabyte (!) of zeros to get even remotely close to being finite.
    // This is not exactly a use case we need to cater to.
    while number.first() == Some(&b'0') {
        number = &number[1..];
    }
    if number.len() >= 18 {
        return match sign {
            Sign::Positive => ShortcutToInf,
            Sign::Negative => ShortcutToZero,
        };
    }
    let abs_exp = num::from_str_unchecked(number);
    let e = match sign {
        Sign::Positive => abs_exp as i64,
        Sign::Negative => -(abs_exp as i64),
    };
    Valid(Decimal::new(integral, fractional, e))
}
/// Exponent extraction and error checking.
Exponent extraction and error checking.
Exponent extraction and error checking .
fn parse_exp<'a>(integral: &'a [u8], fractional: &'a [u8], rest: &'a [u8]) -> ParseResult<'a> {
    let (sign, rest) = match rest.first() {
        Some(&b'-') => (Sign::Negative, &rest[1..]),
        Some(&b'+') => (Sign::Positive, &rest[1..]),
        _ => (Sign::Positive, rest),
    };
    let (mut number, trailing) = eat_digits(rest);
    if !trailing.is_empty() {
        return Invalid; // Trailing junk after exponent
    }
    if number.is_empty() {
        return Invalid; // Empty exponent
    }
    // At this point, we certainly have a valid string of digits. It may be too long to put into
    // an `i64`, but if it's that huge, the input is certainly zero or infinity. Since each zero
    // in the decimal digits only adjusts the exponent by +/- 1, at exp = 10^18 the input would
    // have to be 17 exabyte (!) of zeros to get even remotely close to being finite.
    // This is not exactly a use case we need to cater to.
    while number.first() == Some(&b'0') {
        number = &number[1..];
    }
    if number.len() >= 18 {
        return match sign {
            Sign::Positive => ShortcutToInf,
            Sign::Negative => ShortcutToZero,
        };
    }
    let abs_exp = num::from_str_unchecked(number);
    let e = match sign {
        Sign::Positive => abs_exp as i64,
        Sign::Negative => -(abs_exp as i64),
    };
    Valid(Decimal::new(integral, fractional, e))
}
fn parse_exp < ' a > ( integral : & ' a [ u8 ] , fractional : & ' a [ u8 ] , rest : & ' a [ u8 ] ) -> ParseResult < ' a > { let ( sign , rest ) = match rest . first ( ) { Some ( & b'-' ) => ( Sign :: Negative , & rest [ 1 .. ] ) , Some ( & b'+' ) => ( Sign :: Positive , & rest [ 1 .. ] ) , _ => ( Sign :: Positive , rest ) , } ; let ( mut number , trailing ) = eat_digits ( rest ) ; if ! trailing . is_empty ( ) { return Invalid ; // Trailing junk after exponent } if number . is_empty ( ) { return Invalid ; // Empty exponent } // At this point, we certainly have a valid string of digits. It may be too long to put into // an `i64`, but if it's that huge, the input is certainly zero or infinity. Since each zero // in the decimal digits only adjusts the exponent by +/- 1, at exp = 10^18 the input would // have to be 17 exabyte (!) of zeros to get even remotely close to being finite. // This is not exactly a use case we need to cater to. while number . first ( ) == Some ( & b'0' ) { number = & number [ 1 .. ] ; } if number . len ( ) >= 18 { return match sign { Sign :: Positive => ShortcutToInf , Sign :: Negative => ShortcutToZero , } ; } let abs_exp = num :: from_str_unchecked ( number ) ; let e = match sign { Sign :: Positive => abs_exp as i64 , Sign :: Negative => - ( abs_exp as i64 ) , } ; Valid ( Decimal :: new ( integral , fractional , e ) ) }
Exponent extraction and error checking.
Exponent extraction and error checking .
integral
&'a [u8]
fractional
&'a [u8]
rest
&'a [u8]
integral
&'a [u8]
fractional
&'a [u8]
rest
&'a [u8]