0

I'm using toml to parse data, and I have this struct:

use serde_derive::Deserialize;
use toml::value::Datetime;

#[derive(Debug, Deserialize)]
pub struct Trade {
    pub action: Action,
    pub date_time: Datetime,
    pub exchange: Exchange,
    pub fee: i64,
    pub id: Option<String>,
    pub matched: Option<bool>,
    pub price: i64,
    pub quantity: i64,
}

I'd like to replace the integers (i64) with BigInt, a struct from the num library.

Is this possible? Do I have to implement the Deserialize trait myself?

Paul Razvan Berg
  • 16,949
  • 9
  • 76
  • 114

1 Answers1

4

In general, you cannot. See How do I implement a trait I don't own for a type I don't own? for more details

For your specific case, num already has a feature for that:

The serde feature enables serialization for types in num-bigint, num-complex, and num-rational.

so just use it:

[dependencies.num]
version = "0.3"
features = ["serde"]
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Stargateur
  • 24,473
  • 8
  • 65
  • 91