Struct EnumType
pub struct EnumType { /* private fields */ }Expand description
An enum type is a special type that takes one of two forms:
- C-like enumeration of named integer values, where the discriminant is the integral type
- Rust-like enumeration over the variant types, tagged with a value of the discriminant type
In 1, the variants are all of the same type as the discriminant. In 2, the variants may each be different shape.
Implementations§
§impl EnumType
impl EnumType
pub fn new<I>(
name: Arc<str>,
discriminant: Type,
variants: I,
) -> Result<EnumType, InvalidEnumTypeError>where
I: IntoIterator<Item = Variant>,
pub fn new<I>(
name: Arc<str>,
discriminant: Type,
variants: I,
) -> Result<EnumType, InvalidEnumTypeError>where
I: IntoIterator<Item = Variant>,
Construct a new EnumType with the given name, discriminant type, and variants.
pub fn phantom(
name: Arc<str>,
discriminant: Type,
) -> Result<EnumType, InvalidEnumTypeError>
pub fn phantom( name: Arc<str>, discriminant: Type, ) -> Result<EnumType, InvalidEnumTypeError>
Construct a new EnumType representing a phantom type with the given name and discriminant
pub fn discriminant(&self) -> &Type
pub fn discriminant(&self) -> &Type
Returns the discriminant type for this enum
pub fn variant_offsets(&self) -> impl ExactSizeIterator
pub fn variant_offsets(&self) -> impl ExactSizeIterator
Returns an iterator over the variants of this enumeration with their offset from the base of the enum (i.e. given a pointer to a value of this type, the offset can be used to derive a pointer to the variant value type).
pub fn discriminant_values(&self) -> impl ExactSizeIterator
pub fn discriminant_values(&self) -> impl ExactSizeIterator
Returns an iterator over the discriminant values of this enum.
The order of values produced by this iterator is identical to the order of the variants.
Discriminant values are computed as follows:
- Variants either have an explicit discriminant value set, or receive a discriminant value
derived from the preceding variant by adding
1to it. - If the first variant has no explicit value, the discriminant value range begins at
0. - If the the end of the valid discriminant value range is reached before the last variant, this function will panic with an assertion pointing to the invalid variant.
pub fn is_phantom(&self) -> bool
pub fn is_phantom(&self) -> bool
Returns true if this type has no variants, and thus no physical in-memory representation.
pub fn is_zst(&self) -> bool
pub fn is_zst(&self) -> bool
Returns true if this type has no physical in-memory representation, i.e. it is a phantom
pub fn is_c_like(&self) -> bool
pub fn is_c_like(&self) -> bool
Returns true if this enum type is a C-like enum, i.e. where the type is equivalent to the discriminant value type.
pub fn size_in_bytes(&self) -> usize
pub fn size_in_bytes(&self) -> usize
Returns the size in bytes of this type, without alignment padding.
pub fn size_in_bits(&self) -> usize
pub fn size_in_bits(&self) -> usize
Returns the size in bits of this type, without alignment padding.
pub fn min_alignment(&self) -> usize
pub fn min_alignment(&self) -> usize
Returns the minimum alignment, in bytes, of this type
Trait Implementations§
§impl<'de> Deserialize<'de> for EnumType
impl<'de> Deserialize<'de> for EnumType
§fn deserialize<__D>(
__deserializer: __D,
) -> Result<EnumType, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<EnumType, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
§impl PrettyPrint for EnumType
impl PrettyPrint for EnumType
§fn to_pretty_string(&self) -> String
fn to_pretty_string(&self) -> String
§fn pretty_print(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn pretty_print(&self, f: &mut Formatter<'_>) -> Result<(), Error>
§impl Serialize for EnumType
impl Serialize for EnumType
§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Eq for EnumType
impl StructuralPartialEq for EnumType
Auto Trait Implementations§
impl Freeze for EnumType
impl RefUnwindSafe for EnumType
impl Send for EnumType
impl Sync for EnumType
impl Unpin for EnumType
impl UnsafeUnpin for EnumType
impl UnwindSafe for EnumType
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<D> OwoColorize for D
impl<D> OwoColorize for D
§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg] or
a color-specific method, such as [OwoColorize::green], Read more§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg] or
a color-specific method, such as [OwoColorize::on_yellow], Read more