feat: Add serde support behind a feature flag #4
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/serde"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Adds a
serdefeature, off by default, givingMoney,MoneyBag,Currency,IsoAlphabeticCode,IsoNumericCode, andRoundingModeaSerializeand aDeserializeimpl. The wire shapes are documented in theREADME, under Features.
The impls are lucre's own end to end, down to the text an amount is written
as. rust_decimal's
serde-floatandserde-strfeatures are crate-wide andadditive, so deferring to
Decimal's impls would have let any crate sharing abuild change what lucre writes.
rust_decimalis now depended on with itsdefault features off,
stdaside, which also stops lucre handingDecimal: Serializeto downstream crates that never asked for it.Reading a
MoneyBagtotals whatever the document says rather than insistingit already be in the shape a bag would have written: a zero balance leaves no
currency behind, and a currency named twice is summed, matching
FromIteratorand
+=.IsoNumericCodegainsTryFrom<u32>, without which deserialization wouldhave been the only way to build one from an integer.
The first commit is separate:
Money::from_majornow rescales to thecurrency's minor digits, so the three constructors produce the same
Decimalfor the same money.