#[derive(Deserialize, Serialize)]
enum En {
A(i32),
B(String)
}
#[derive(Deserialize, Serialize)]
struct Data {
data: Mutex<HashSet<En>>
}
When using this structure, serializing the struct outputs something like {"data": [{"A": 0}, {"B": "String"}]}
, I'd like to remove the list from the json and combine the data into one map ({"data": {"A": 0, "B": "String"}}
).
I'd like to keep the HashSet for unique data and to force each variant's type, is there a way to do that without having to implement my own serialize or deserialize methods.
I've tried using serde_as from the serde_with crate with the as
type Mutex<HashMap<String, _>>
, though I keep getting errors saying "the trait bound HashMap<Same, Same>: SerializeAs<HashSet<En>>
is not satisfied"
I have a partial solution using a HashMap instead of a HashSet, though I'd prefer if it was possible to keep using a set.