#[repr(C)]pub struct Variant {
pub name: &'static str,
pub discriminant: Option<i64>,
pub attributes: &'static [VariantAttribute],
pub data: StructType,
pub doc: &'static [&'static str],
}Expand description
Describes a variant of an enum
Fields§
§name: &'static strName of the variant, e.g. Foo for enum FooBar { Foo, Bar }
discriminant: Option<i64>Discriminant value (if available). Might fit in a u8, etc.
attributes: &'static [VariantAttribute]Attributes set for this variant via the derive macro
data: StructTypeFields for this variant (empty if unit, number-named if tuple). IMPORTANT: the offset for the fields already takes into account the size & alignment of the discriminant.
doc: &'static [&'static str]Doc comment for the variant
Implementations§
Source§impl Variant
impl Variant
Sourcepub fn has_attr(&self, ns: Option<&str>, key: &str) -> bool
pub fn has_attr(&self, ns: Option<&str>, key: &str) -> bool
Checks whether the Variant has an attribute with the given namespace and key.
Use None for builtin attributes, Some("ns") for namespaced attributes.
Sourcepub fn get_attr(&self, ns: Option<&str>, key: &str) -> Option<&Attr>
pub fn get_attr(&self, ns: Option<&str>, key: &str) -> Option<&Attr>
Gets an attribute by namespace and key.
Use None for builtin attributes, Some("ns") for namespaced attributes.
Sourcepub fn has_builtin_attr(&self, key: &str) -> bool
pub fn has_builtin_attr(&self, key: &str) -> bool
Checks whether the Variant has a builtin attribute with the given key.
Sourcepub fn get_builtin_attr(&self, key: &str) -> Option<&Attr>
pub fn get_builtin_attr(&self, key: &str) -> Option<&Attr>
Gets a builtin attribute by key.
Sourcepub fn is_text(&self) -> bool
pub fn is_text(&self) -> bool
Returns true if this variant has the #[facet(html::text)] or #[facet(xml::text)] attribute.
When serializing to HTML/XML, variants marked as text should be serialized as text content rather than as elements.
Sourcepub fn is_custom_element(&self) -> bool
pub fn is_custom_element(&self) -> bool
Returns true if this variant has the #[facet(html::custom_element)] or
#[facet(xml::custom_element)] attribute.
When deserializing HTML/XML, variants marked as custom_element act as a catch-all
for unknown element names. The element’s tag name is stored in the variant’s tag field.