serde
serde copied to clipboard
accept #[serde(other)] on non-unit enum variants
Hello !
What would you think of accepting the #[serde(other) attribute on struct- and tuple- enum variants ?
Currently, the following code :
#[derive(Deserialize, Debug)]
enum Item {
Foo,
Bar,
#[serde(other)]
Other(Contents),
}
raises the following compilation error :
error: #[serde(other)] must be on a unit variant
This would allow collecting the data corresponding to an unknown or unexpected enum variant.
This would be very helpful for instance in serde-xml-rs to parse data from complex xml schema without all possible tags in advance. (see https://github.com/RReverser/serde-xml-rs/issues/55)
https://github.com/serde-rs/serde/issues/912 is sort of already tracking this. It started off asking for #[serde(other)] in general; then when that was implemented for unit variants it also asked for that on variants with data.
Try use serde-enum-str , the examples
See https://github.com/serde-rs/serde/issues/912#issuecomment-1868785603