How can I accomplish this? This doesn't compile and is this something that is achievable. What am I missing here?
#[derive(Serialize, Deserialize)]
struct Test<'a, T>
where T : Serialize + Deserialize<'a>
{
t_ : T,
marker_ : PhantomData<&'a T>
}
impl<'a, T> Test<'a, T>
where T : Serialize + Deserialize<'a>
{
fn new(t : T) -> Self
{
return Self {
t_ : t,
marker_ : PhantomData
};
}
}
These are the errors I get and can't figure out how to make progress.
error[E0283]: type annotations needed: cannot satisfy `T: Deserialize<'a>`
--> src/lib.rs:6:27
|
6 | where T : Serialize + Deserialize<'a>
| ^^^^^^^^^^^^^^^
|
= note: cannot satisfy `T: Deserialize<'a>`
error[E0283]: type annotations needed: cannot satisfy `T: Deserialize<'a>`
--> src/lib.rs:5:8
|
5 | struct Test<'a, T>
| ^^^^^^^^^^^
|
= note: cannot satisfy `T: Deserialize<'a>`
note: required by a bound in `Test`
--> src/lib.rs:6:27
|
5 | struct Test<'a, T>
| ---- required by a bound in this
6 | where T : Serialize + Deserialize<'a>
| ^^^^^^^^^^^^^^^ required by this bound in `Test`
error[E0283]: type annotations needed: cannot satisfy `T: Deserialize<'_>`
--> src/lib.rs:4:21
|
4 | #[derive(Serialize, Deserialize)]
| ^^^^^^^^^^^
|
= note: cannot satisfy `T: Deserialize<'_>`
note: required for `__Visitor<'de, 'a, T>` to implement `Visitor<'de>`
--> src/lib.rs:4:21
|
4 | #[derive(Serialize, Deserialize)]
| ^^^^^^^^^^^
= note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info)
For more information about this error, try `rustc --explain E0283`.
struct Test is just bare bones and can have more fields. But the key is that needs to be generic enough to hold a type T that can be serialized and deserialized.