#[non_exhaustive]pub struct EnumDef {
pub name: String,
pub repr: Scalar,
pub variants: Vec<Variant>,
pub other: Option<String>,
pub doc: Option<String>,
pub default: Option<String>,
pub derives: Vec<Derive>,
pub other_doc: Option<String>,
}Expand description
An enumeration of named values, with an optional fallback variant for unlisted values.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.name: StringThe type name.
repr: ScalarThe value’s type.
variants: Vec<Variant>The variants, in declaration order.
other: Option<String>The fallback variant, which holds an unlisted value. None means every value is listed.
doc: Option<String>Documentation.
default: Option<String>The variant marked #[default], which needs an ungated Default derive.
derives: Vec<Derive>Derives for this enumeration, written after the module’s.
other_doc: Option<String>Documentation for the fallback variant. None writes a general sentence.
Implementations§
Source§impl EnumDef
impl EnumDef
Sourcepub fn new(name: &str, repr: Scalar, variants: Vec<Variant>) -> Self
pub fn new(name: &str, repr: Scalar, variants: Vec<Variant>) -> Self
An enumeration with no fallback, so it must list every value.
Sourcepub fn with_other_doc(self, doc: &str) -> Self
pub fn with_other_doc(self, doc: &str) -> Self
Sets the fallback variant’s documentation.
Sourcepub fn with_default(self, variant: &str) -> Self
pub fn with_default(self, variant: &str) -> Self
Marks variant #[default], which the derives must match with an ungated Default.
The variant must be a listed one, not the fallback, which carries a value.
Sourcepub fn with_derives(self, derives: Vec<Derive>) -> Self
pub fn with_derives(self, derives: Vec<Derive>) -> Self
Sets the derives written on this enumeration, after the module’s.
Sourcepub fn with_other(self, other: &str) -> Self
pub fn with_other(self, other: &str) -> Self
Adds a fallback variant other(repr) that holds any unlisted value.