Expand description

Provides a target for serde(with = ...) that permits deserializing Decimal values from primitive integers, Strings, or str.

use std::convert::TryFrom;
use serde::{Deserialize, Serialize};
const N: usize = 12;

#[repr(transparent)]
#[derive(Debug, PartialEq, PartialOrd, Deserialize, Serialize)]
pub struct PrimitiveDeserializableDecimal<const N: usize>(
    #[serde(with = "dec::serde_decimal_from_non_float_primitives")] pub dec::Decimal<N>,
);

let v: PrimitiveDeserializableDecimal<N> =
          serde_json::from_str("-1").expect("deserialization works");

assert_eq!(dec::Decimal::try_from(-1i32).unwrap(), v.0);

Note that the feature provided by this crate is only compatible with self-describing input formats, such as JSON, as it relies on Deserialize::deserialize_any.

Functions

  • Deserializes the value permitting a conversion to a Decimal<N> from primitive integers (i8, u8, i16, u16, i32, u32, i64, u64, i128, u128), String, and str.
  • Serialize d using the default, derivsed Serialize implementation.