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?
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
, andnum-rational
.
so just use it:
[dependencies.num]
version = "0.3"
features = ["serde"]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.