usesuper::docs::Docs; usesuper::{AttrInheritContext, Attrs, Ident, Method}; use quote::ToTokens;
/// A fieldless enum declaration in an FFI module. #[derive(Clone, Serialize, Debug, Hash, PartialEq, Eq)] #[non_exhaustive] pubstructEnum { pub name: Ident, pub docs: Docs, /// A list of variants of the enum. (name, discriminant, docs, attrs) pub variants: Vec<(Ident, isize, Docs, Attrs)>, pub methods: Vec<Method>, pub attrs: Attrs,
}
implEnum { /// Extract an [`Enum`] metadata value from an AST node. pubfn new(enm: &syn::ItemEnum, parent_attrs: &Attrs) -> Enum { letmut last_discriminant = -1; if !enm.generics.params.is_empty() { // Generic types are not allowed. // Assuming all enums cannot have lifetimes? We don't even have a // `lifetimes` field. If we change our minds we can adjust this later // and update the `CustomType::lifetimes` API accordingly.
panic!("Enums cannot have generic parameters");
}
letmut attrs = parent_attrs.clone();
attrs.add_attrs(&enm.attrs); let variant_parent_attrs = attrs.attrs_for_inheritance(AttrInheritContext::Variant);
Enum {
name: (&enm.ident).into(),
docs: Docs::from_attrs(&enm.attrs),
variants: enm
.variants
.iter()
.map(|v| { let new_discriminant = v
.discriminant
.as_ref()
.map(|d| { // Reparsing, signed literals are represented // as a negation expression let lit: Result<syn::Lit, _> = syn::parse2(d.1.to_token_stream()); iflet Ok(syn::Lit::Int(ref lit_int)) = lit {
lit_int.base10_parse::<isize>().unwrap()
} else {
panic!("Expected a discriminant to be a constant integer");
}
})
.unwrap_or_else(|| last_discriminant + 1);
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.0Bemerkung:
(vorverarbeitet am 2026-06-19)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.