/// Attempt to parse this [`Value`] as a PHC-encoded decimal (i.e. integer).
///
/// Decimal values are integers which follow the rules given in the
/// ["Decimal Encoding" section of the PHC string format specification][1].
///
/// The decimal encoding rules are as follows:
/// > For an integer value x, its decimal encoding consist in the following:
/// >
/// > - If x < 0, then its decimal encoding is the minus sign - followed by the decimal
/// >   encoding of -x.
/// > - If x = 0, then its decimal encoding is the single character 0.
/// > - If x > 0, then its decimal encoding is the smallest sequence of ASCII digits that
/// >   matches its value (i.e. there is no leading zero).
/// >
/// > Thus, a value is a valid decimal for an integer x if and only if all of the following hold true:
/// >
/// > - The first character is either a - sign, or an ASCII digit.
/// > - All characters other than the first are ASCII digits.
/// > - If the first character is - sign, then there is at least another character, and the
/// >   second character is not a 0.
/// > - If the string consists in more than one character, then the first one cannot be a 0.
///
/// Note: this implementation does not support negative decimals despite
/// them being allowed per the spec above. If you need to parse a negative
/// number, please parse it from the string representation directly e.g.
/// `value.as_str().parse::<i32>()`
///
/// [1]: https://github.com/P-H-C/phc-string-format/blob/master/phc-sf-spec.md#decimal-encoding
Attempt to parse this [`Value`] as a PHC-encoded decimal .
Decimal values are integers which follow the rules given in the
["Decimal Encoding" section of the PHC string format specification][1].

The decimal encoding rules are as follows:
> For an integer value x, its decimal encoding consist in the following:
>
> - If x < 0, then its decimal encoding is the minus sign - followed by the decimal
>   encoding of -x.
> - If x = 0, then its decimal encoding is the single character 0.
> - If x > 0, then its decimal encoding is the smallest sequence of ASCII digits that
>   matches its value .
>
> Thus, a value is a valid decimal for an integer x if and only if all of the following hold true:
>
> - The first character is either a - sign, or an ASCII digit.
> - All characters other than the first are ASCII digits.
> - If the first character is - sign, then there is at least another character, and the
>   second character is not a 0.
> - If the string consists in more than one character, then the first one cannot be a 0.

this implementation does not support negative decimals despite
them being allowed per the spec above. If you need to parse a negative
number, please parse it from the string representation directly e.g.


Attempt to parse this [ ` Value ` ] as a PHC - encoded decimal . Decimal values are integers which follow the rules given in the [ " Decimal Encoding " section of the PHC string format specification ] [ 1 ] . The decimal encoding rules are as follows : > For an integer value x its decimal encoding consist in the following : > > - If x < 0 then its decimal encoding is the minus sign - followed by the decimal > encoding of - x . > - If x = 0 then its decimal encoding is the single character 0 . > - If x > 0 then its decimal encoding is the smallest sequence of ASCII digits that > matches its value . > > Thus a value is a valid decimal for an integer x if and only if all of the following hold true : > > - The first character is either a - sign or an ASCII digit . > - All characters other than the first are ASCII digits . > - If the first character is - sign then there is at least another character and the > second character is not a 0 . > - If the string consists in more than one character then the first one cannot be a 0 . this implementation does not support negative decimals despite them being allowed per the spec above . If you need to parse a negative number please parse it from the string representation directly e . g .
pub fn decimal(&self) -> Result<Decimal> {
        let value = self.as_str();
        // Empty strings aren't decimals
        if value.is_empty() {
            return Err(Error::ParamValueInvalid(InvalidValue::Malformed));
        }
        // Ensure all characters are digits
        for c in value.chars() {
            if !matches!(c, '0'..='9') {
                return Err(Error::ParamValueInvalid(InvalidValue::InvalidChar(c)));
            }
        }
        // Disallow leading zeroes
        if value.starts_with('0') && value.len() > 1 {
            return Err(Error::ParamValueInvalid(InvalidValue::InvalidFormat));
        }
        value.parse().map_err(|_| {
            // In theory a value overflow should be the only potential error here.
            // When `ParseIntError::kind` is stable it might be good to double check:
            // <https://github.com/rust-lang/rust/issues/22639>
            Error::ParamValueInvalid(InvalidValue::InvalidFormat)
        })
    }
pub fn decimal ( & self ) -> Result < Decimal > { let value = self . as_str ( ) ; // Empty strings aren't decimals if value . is_empty ( ) { return Err ( Error :: ParamValueInvalid ( InvalidValue :: Malformed ) ) ; } // Ensure all characters are digits for c in value . chars ( ) { if ! matches ! ( c '0' '9' ) { return Err ( Error :: ParamValueInvalid ( InvalidValue :: InvalidChar ( c ) ) ) ; } } // Disallow leading zeroes if value . starts_with ( '0' ) && value . len ( ) > 1 { return Err ( Error :: ParamValueInvalid ( InvalidValue :: InvalidFormat ) ) ; } value . parse ( ) . map_err ( | _ | { // In theory a value overflow should be the only potential error here. // When `ParseIntError::kind` is stable it might be good to double check: // <https://github.com/rust-lang/rust/issues/22639> Error :: ParamValueInvalid ( InvalidValue :: InvalidFormat ) } ) }
Attempt to parse this [`Value`] as a PHC-encoded decimal (i.e.
Attempt to parse this [ ` Value ` ] as a PHC - encoded decimal ( i . e .
&self