Skip to main content

deserialize_decimal_token

Function deserialize_decimal_token 

Source
pub fn deserialize_decimal_token<'de, D>(
    deserializer: D,
) -> Result<Decimal, D::Error>
where D: Deserializer<'de>,
Expand description

Deserializes a Decimal from the source text of a JSON number or numeric string.

Numeric tokens keep their source digits instead of passing through f64. Representable values, including scientific notation, parse exactly. Values with fractional digits beyond Decimal’s maximum scale (28) round as strings do in deserialize_decimal. Unlike deserialize_decimal, null and empty strings are errors.

The raw token is only available from direct JSON input: serde’s internally tagged and untagged enum buffers cannot carry it. A buffered serde_json::Value renders its number, which keeps the source digits only with serde_json/arbitrary_precision. For borrowed JSON text, deserialize_decimal_token_borrowed reads the same tokens without copying them.

§Errors

Returns an error if the token is null, an empty string, not a decimal, or outside Decimal’s range.