strong-xml
strong-xml copied to clipboard
Pass all childs types to enum?
I somehow possible to skip the child definition and just for example use:
#[xml(child = "*")]
childs: Vec<All>,
or
#[xml(childall)]
childs: Vec<All>,
I have an enum like that:
#[derive(XmlWrite, XmlRead, PartialEq, Debug)]
pub enum All {
#[xml(tag = "Figura")] Figure(Figure),
#[xml(tag = "Pomiar")] Measurement(Measurement),
#[xml(tag = "Wyswietlacz")] Display(Display),
#[xml(tag = "Grupa")] Group(Group),
#[xml(tag = "GrupaObiektow")] GroupObjects(GroupObjects),
#[xml(tag = "Opis")] Desc(Desc),
}
And doing:
#[xml(child = "Figura", child = "Pomiar", child = "Wyswietlacz", child = "Grupa", child="GrupaObiektow", child="Opis")]
childs: Vec<All>,
Is just double work, or even in my case four times repeating that same thing because Group and GroupObjects also contain child's. The enum have all information need to parse child's, and it could just return some error "VariantNotFound" when an unknown child appears.
Currently, the child tags are used as literals when expanding the read logic on the containing structure. I don't see a way within the rust macro system to access the child type attributes. However, it should be possible to provide the child type tags from an associated function that's called during parsing. It will only handle constant data and should thus be optimized into constant comparisons, much like right now. I'll try to get a PR going.