Serde - how to deserialize statefully?

Hypothetically, let's say you already have a Vec with elements in it, and you'd like to throw more elements into it without going through a middleware Vec. Allegedly this is what DeserializeSeed is for, but... far as we can tell, there's no way to pass a DeserializeSeed to e.g. serde_json? Only stateless Deserialize.

What about constructing a serde_json::Deserializer and passing that to DeserializeSeed::deserialize()?

1 Like

That works we guess... Is it common enough practice among serde-based deserializers to expose those that way, so that one can expect it for all sorts of formats?

All of the crates that implement deserialization from a format would have to implement Deserializer so it's just a matter of having that be part of the public interface. With a quick look at some of the most popular deserialization crates, all of the ones I've seen do expose a struct named Deserializer which implements serde::de::Deserializer

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.