I try to implement my own custom Serde deserializer. I made some progress with simple data types, but struggle to get deserialize_struct working. The signature looks like
fn deserialize_struct<V>( self, name: &'static str, fields: &'static [&'static str], visitor: V, ) -> Result<V::Value, Self::Error> where V: Visitor<'de>, { // ??? } so I'm obviously expected to create an instance of V::Value and return it. For my tests I use the following struct
#[derive(Debug, Deserialize)] struct FakeA { x: String, } which is deserialized as part of a HashMap<String, FakeA>. When hitting the above trait method all the parameters look good to me. V::Value is actually FakeA. But how do I create an instance? The Json-example in the docs delegates to deserialize_map which is not helpful for me. I tried
V::Value::deserialize(self) but this does not work, because V::Value is not required to implement Deserialize.
Based on my Serde experiences so far, I expect that I miss some additional layer of indirection. Any hint in the right direction would be highly appreciated.
1 post - 1 participant
