Closed cyqsimon closed 1 month ago
No, there is nothing like that in the crate. It seems possible to implement this for a specific case.
As a general implementation, I see two problems right now. You somehow need to make the key
part configurable. This is not a problem for a specific implementation. However, to make it general, you can't simply pass the string as generic type parameter, as const generics does not cover strings and adt_const_params
is not anywhere close to implementation.
In the example implementation below I used serde(flatten)
to implement it. However, there are some downsides with flatten
, like extra buffering, and that the added key
could interfere with deserialization.
Got it. Don't quite understand everything you said here, but the TLDR seems to be that there are technical difficulties with a generic implementation.
Yeah, using #[serde(into)]
and #[serde(from)]
seems easy enough. Will do that.
Not sure how exactly you want to handle this issue, so I'll leave it as is. Please do with it what you see fit.
KeyValueMap
serializes aVec<T>
into a map, but I'm looking for the inverse.Is there something that serializes a
*Map<K, V>
into a list, whereK
becomes a field inV
, similar to internally tagged enum representation?E.g.
Given:
I would like to have this:
... serialize into this: