#[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>,
}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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
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.
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_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.
Trait Implementations§
impl Eq for EnumDef
impl StructuralPartialEq for EnumDef
Auto Trait Implementations§
impl Freeze for EnumDef
impl RefUnwindSafe for EnumDef
impl Send for EnumDef
impl Sync for EnumDef
impl Unpin for EnumDef
impl UnsafeUnpin for EnumDef
impl UnwindSafe for EnumDef
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more