mamrhein / fpdec.rs

Fast implementation of Decimal fixed-point arithmetics
BSD 3-Clause "New" or "Revised" License
17 stars 4 forks source link

Adds `serde_derive` feature #2

Closed MathisWellmann closed 1 year ago

MathisWellmann commented 1 year ago

to allow serialization and deserialization of the Decimal struct. It only takes effect if the dependency is specified as such:

fpdec = { version = "*", features = ["serde_derive"] }

The reason for this addition is that I would like to be able to rely on serde support in lfest to serialize the BaseCurrency and QuoteCurrency among others. I would love to see this change get merged and published so a new version of lfest can be published as well.

Thank you for such an amazing crate, I'm glad I found it!

mamrhein commented 1 year ago

Thx for the PR. Unfortunately, Decimal is using an i128 integer for the coefficient and serde doesn't seem to support integers larger than 64-bit out of the box. I'll have to dig into serde to find a solution.

MathisWellmann commented 1 year ago

After some re-thinking, I will not directly serialize or deserialize the Decimal type as its rather confusing from a user-facing perspective to have to specify the inner fields. Consider this PR low priority or feel free to close it as well. Cheers!

mamrhein commented 1 year ago

I've created a branch 'serde'. The feature 'serde_as_str' allows Decimal instances to be serialized to / deserialized from String. Maybe you want to give it a try. If so, please let me know what you think about it.

MathisWellmann commented 1 year ago

Just tried out your new feature branch and it looks excellent. Using the From<Decimal> and TryFrom<String> trait implementations through the serde features is a fantastic way, especially from the users perspective (As they should not be bothered to specify the coeff). Having to enable both serde and serde_as_str features is the right choice as well, as not everyone will want to use String as the intermediate representation. Integrating the feature is straightforward as well. I certainly would be happy seeing these changes in a crates.io release. Gute Arbeit :)

mamrhein commented 1 year ago

Solved by adding feature 'serde-as-str'. See version 0.6.0.