I'm deserializing a struct from JSON:
fn main() {
let raw_json = r#"{"error": {"msg": "I am an error message"}}"#;
let error: Error = json::decode(raw_json).unwrap();
}
struct Error {
message: &'static str
}
impl<D: Decoder<E>, E> Decodable<D, E> for Error {
fn decode(d: &mut D) -> Result<Error, E> {
d.read_struct("error", 1, |d| {
Ok(Error{
message: try!(d.read_struct_field("msg", 0u, |d| Decodable::decode(d)))
})
})
}
}
But getting this error:
failed to find an implementation of trait serialize::serialize::Decodable<D,E> for &'static str
Adding lifetime to message does not help.
Turns out there is no implementation of Decodable trait for &str, but only for String
How do I deserialize my JSON into &str struct field?