I have this simple struct below that I wanted to deserialize using serde. but it gave me conflicting lifetime error. I don't understand how that error shows up
#[derive(Serialize, Deserialize)]
pub struct Transaction<'a> {
timestamp: i64,
next: Option<&'a str>,
prev: Option<&'a str>,
}
Error:
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'de` due to conflicting requirements
--> src/main.rs:4:21
|
4 | #[derive(Serialize, Deserialize)]
| ^^^^^^^^^^^
|
note: first, the lifetime cannot outlive the lifetime 'de as defined on the impl at 4:21...
--> src/main.rs:4:21
|
4 | #[derive(Serialize, Deserialize)]
| ^^^^^^^^^^^
note: ...so that types are compatible (expected serde::de::SeqAccess<'_>, found serde::de::SeqAccess<'de>)
--> src/main.rs:4:21
|
4 | #[derive(Serialize, Deserialize)]
| ^^^^^^^^^^^
note: but, the lifetime must be valid for the lifetime 'a as defined on the impl at 4:21...
--> src/main.rs:4:21
|
4 | #[derive(Serialize, Deserialize)]
| ^^^^^^^^^^^
note: ...so that types are compatible (expected serde::Deserialize<'_>, found serde::Deserialize<'_>)
--> src/main.rs:4:21
|
4 | #[derive(Serialize, Deserialize)]
| ^^^^^^^^^^^
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'de` due to conflicting requirements
--> src/main.rs:4:21
|
4 | #[derive(Serialize, Deserialize)]
| ^^^^^^^^^^^
|
note: first, the lifetime cannot outlive the lifetime 'de as defined on the impl at 4:21...
--> src/main.rs:4:21
|
4 | #[derive(Serialize, Deserialize)]
| ^^^^^^^^^^^
note: ...so that types are compatible (expected serde::de::MapAccess<'_>, found serde::de::MapAccess<'de>)
--> src/main.rs:4:21
|
4 | #[derive(Serialize, Deserialize)]
| ^^^^^^^^^^^
note: but, the lifetime must be valid for the lifetime 'a as defined on the impl at 4:21...
--> src/main.rs:4:21
|
4 | #[derive(Serialize, Deserialize)]
| ^^^^^^^^^^^
note: ...so that types are compatible (expected serde::Deserialize<'_>, found serde::Deserialize<'_>)
--> src/main.rs:4:21
|
4 | #[derive(Serialize, Deserialize)]
| ^^^^^^^^^^^