num-bigint icon indicating copy to clipboard operation
num-bigint copied to clipboard

How to implement Serialize and Deserialize

Open MathieuDutSik opened this issue 7 years ago • 3 comments

I would to use serde json serialization for BigUint type. How can one do that?

If I write #[derive(Serialize, Deserialize)] pub struct Account { value: BigUint } Then I get the error | ^^^^^^^^^^^^^^^ the trait serde::Deserialize<'_> is not implemented for num_bigint::BigUint

How can i do this implementation? Is there a standard implementation?

MathieuDutSik avatar Feb 10 '19 11:02 MathieuDutSik

You need to enable the "serde" feature of num-bigint. See the cargo docs for general instructions about features: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#choosing-features

cuviper avatar Feb 10 '19 19:02 cuviper

Do you think it would make sense to have all features on by default? Someone who wants to disable a feature probably knows what they're doing (at least more than average). It feels beginner-unfriendly as-is.

maxbla avatar Jul 29 '19 09:07 maxbla

No, I'd rather not add to the build time by default. But we could probably do a better job of documenting the available features and how to use them (plus their associated minimum rustc).

cuviper avatar Jul 29 '19 19:07 cuviper