Module rust_decimal::serde::str

source ·
Available on crate feature serde and (crate features serde-with-str or serde-with-float or serde-with-arbitrary-precision) and crate feature serde-with-str only.
Expand description

Serialize/deserialize Decimals as strings. This is particularly useful when using binary encoding formats.


#[derive(Serialize, Deserialize)]
pub struct StringExample {
    #[serde(with = "rust_decimal::serde::str")]
    value: Decimal,
}

let value = StringExample { value: Decimal::from_str("123.400").unwrap() };
assert_eq!(
    &serde_json::to_string(&value).unwrap(),
    r#"{"value":"123.400"}"#
);

Functions§