-
Notifications
You must be signed in to change notification settings - Fork 23
Description
Here's a thought, something that happens often in practice: you're deserializing something that looks like
{"flags": ["foo", "baz"]}into your own bitflags format which looks like
enum Flags { Foo, Bar, Baz }There's a few ways to do this manually, but wouldn't it be nice if this crate provided some way to do it? Not sure what's the best way, since making it a crate feature would immediately change it for all wrapped enums, whereas it's more of a runtime thing. Perhaps the deserializer could try parsing a sequence if it can't parse an integer? There shouldn't be any ambiguity there. Or maybe a separate public module that can be used with #[serde(with)] - this way some fields can be (de)serialized as ints and some - as sequences.
Also, if doing it by hand and in order to avoid allocations, you might need something like T::N_VARIANTS or ArrayVec<T, T::N_VARIANTS> (if you're sure the flags don't repeat...) so you can instantiate something like [T; T::N_VARIANTS] which currently is not something exposed by any of the traits unless I'm missing something.