windows-rdl 0.100.0

RDL parser library and ECMA-335 generator
Documentation
use super::*;

#[derive(Debug, Clone)]
pub struct Union {
    pub attrs: Vec<syn::Attribute>,
    pub name: syn::Ident,
    pub fields: Vec<Field>,
}

impl syn::parse::Parse for Union {
    fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
        let attrs = input.call(syn::Attribute::parse_outer)?;
        let _: syn::Token![union] = input.parse()?;
        let name = input.parse()?;

        let content;
        syn::braced!(content in input);

        let fields = content
            .parse_terminated(Field::parse, syn::Token![,])?
            .into_iter()
            .collect();

        Ok(Self {
            attrs,
            name,
            fields,
        })
    }
}

impl Encoder<'_> {
    pub fn encode_union(&mut self, item: &Union) -> Result<(), Error> {
        let name = item.name.to_string();
        self.encode_record(&name, false, true, &item.fields, &item.attrs, None)?;
        Ok(())
    }
}