I'm parsing an INI-style file that uses integers for enumerators.
#[derive(Debug, Deserialize, Serialize)]
pub enum MyThing {
First = 0,
Second = 1,
Third = 2,
}
In the file, the value will get serialized like so:
thing=0
However, Serde by default matches against the variant name rather than the discriminant. Is custom-implementing Deserialize
the cleanest method?
The Serde website has an entire example on how to serialize an enum as a number:
I would believe that this is the best way to do it as it's recommended by the crate authors themselves.