Take the following code snippet (has to be run in cargo, so you can add the serde
feature to num-bigint
):
use num_bigint::BigInt;
use serde_derive::Deserialize;
use std::collections::HashMap;
#[derive(Debug, Deserialize)]
pub struct Trade<'a> {
pub id: &'a str,
pub price: BigInt,
pub quantity: BigInt,
}
#[derive(Debug, Deserialize)]
pub struct TradeTable<'a> {
pub trades: Vec<Trade<'a>>,
}
fn main() {
let mut ether_trades: Vec<Trade> = Vec::new();
ether_trades.push(Trade {
id: "#1",
price: BigInt::from(100),
quantity: BigInt::from(2)
});
let mut trades: HashMap<&str, Vec<Trade>> = HashMap::new();
trades.insert("ETH", ether_trades);
println!("trades: {}", trades);
}
It yields this error when compiling:
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'de` due to conflicting requirements
And this note:
note: first, the lifetime cannot outlive the lifetime `'de` as defined on the impl at 34:17...
Now, I understand that I need to make 'a
live shorter than 'de
, but how can I do that? I don't know where the 'de
lifetime is defined. I tried to use a colon like this:
'de: 'a
But that didn't work.