我正在尝试编写一个派生的结构,serde::Deserialize
但它也有一个应该派生的字段serde::Deserialize
:
extern crate serde;
#[macro_use]
extern crate serde_derive;
use serde::{Deserialize, Serialize};
#[derive(PartialEq, Serialize, Deserialize)]
pub struct Record<'a, T>
where
T: 'a + Serialize + Deserialize<'a>,
{
id: &'a str,
created_at: &'a str,
created_by: Option<&'a str>,
last_updated_at: Option<&'a str>,
object: &'a T,
}
impl<'a, T> Record<'a, T>
where
T: 'a + Serialize + Deserialize<'a>,
{
pub fn new(
id: &'a str,
created_at: &'a str,
created_by: Option<&'a str>,
last_updated_at: Option<&'a str>,
object: &'a T,
) -> Self {
Record {
id,
created_at,
created_by,
last_updated_at,
object,
}
}
}
fn main() {}
我已经更改了一段时间的代码,但我无法编译这个想法。我目前遇到的错误是:
error[E0283]: type annotations required: cannot resolve `T: serde::Deserialize<'a>`
--> src/main.rs:7:32
|
7 | #[derive(PartialEq, Serialize, Deserialize)]
| ^^^^^^^^^^^
|
= note: required by `serde::Deserialize`