use std::collections::HashMap;
fn main() {
let input = r###"
---
key: Key
value: Value
"###;
let x: HashMap<&str, &str> = serde_yaml::from_str(input).unwrap();
// let input = r###"
// {
// "key": "Key",
// "value": "Value"
// }
// "###;
// let x: HashMap<&str, &str> = serde_json::from_str(input).unwrap();
println!("{:?}", x);
}
it will result in compile-time error:
Compiling playground v0.0.1 (/playground)
error: implementation of `serde::de::Deserialize` is not general enough
--> src/main.rs:9:34
|
9 | let x: HashMap<&str, &str> = serde_yaml::from_str(input).unwrap();
| ^^^^^^^^^^^^^^^^^^^^ implementation of `serde::de::Deserialize` is not general enough
|
::: /playground/.cargo/registry/src/github.com-1ecc6299db9ec823/serde-1.0.110/src/de/mod.rs:531:1
|
531 | / pub trait Deserialize<'de>: Sized {
532 | | /// Deserialize this value from the given Serde deserializer.
533 | | ///
534 | | /// See the [Implementing `Deserialize`][impl-deserialize] section of the
... |
569 | | }
570 | | }
| |_- trait `serde::de::Deserialize` defined here
|
= note: `std::collections::HashMap<&str, &str>` must implement `serde::de::Deserialize<'0>`, for any lifetime `'0`...
= note: ...but `std::collections::HashMap<&str, &str>` actually implements `serde::de::Deserialize<'1>`, for some specific lifetime `'1`
error: aborting due to previous error
error: could not compile `playground`.
When running following code snippet:
it will result in compile-time error:
However
serde_json
works for it.Is it a limitation of
serde_yaml
?