Hello,
I'm looking for a solution to serialize a struct without having to fully load it into memory.
// Current status
#[derive(Serialize)]
struct Container {
// [various stuff]
entries: Vec<SomeValue>
}
I'm looking for something that I can serialize to JSON where entries
comes from an external source (a database, a mpsc::Receiver
, Iterator
, ...):
struct Container {
// [various stuff]
entries: mpsc::Receiver<SomeValue>
// or: entries: (Database, Vec<DbId>)
}
Implementing Serialize
is not possible, as serialize
takes &self
, not allowing me to mutate anything. I also investigated driving serde_json::ser::Formatter
directly, but that would mean re-implementing serde_json::Serializer
which I'm trying to avoid.
Is serde_json
/ serde
just not flexible enough for this?