#[repr(C)]pub struct Variant {
pub name: &'static str,
pub rename: Option<&'static str>,
pub discriminant: Option<i64>,
pub attributes: &'static [Attr],
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 }
rename: Option<&'static str>Renamed variant name for serialization/deserialization.
Set by #[facet(rename = "name")] or container-level #[facet(rename_all = "...")].
When present, serializers/deserializers should use this name instead of the variant’s actual name.
discriminant: Option<i64>Discriminant value (if available). Might fit in a u8, etc.
attributes: &'static [Attr]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(custom_element)],
#[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.
Sourcepub fn is_other(&self) -> bool
pub fn is_other(&self) -> bool
Returns true if this variant has the #[facet(other)] attribute.
When deserializing, variants marked as other act as a catch-all
for unknown variant names. This is useful for extensible enums where
unknown tags should be captured rather than rejected.
Sourcepub fn effective_name(&self) -> &'static str
pub fn effective_name(&self) -> &'static str
Returns the effective name for serialization/deserialization.
Returns rename if set, otherwise returns the variant’s actual name.