pub struct EnumType { /* private fields */ }Expand description
Represents the type of an enum.
Implementations§
Source§impl EnumType
impl EnumType
Sourcepub fn new(
enum_name: impl Into<String>,
enum_span: Span,
explicit_inner_type: Type,
variants: Vec<(String, Type)>,
variant_spans: &[Span],
) -> Result<Self, Diagnostic>
pub fn new( enum_name: impl Into<String>, enum_span: Span, explicit_inner_type: Type, variants: Vec<(String, Type)>, variant_spans: &[Span], ) -> Result<Self, Diagnostic>
Constructs a new enum type with a known coerced type.
Validates that all variant types are coercible to the provided type.
Returns an error if any variant cannot be coerced.
Sourcepub fn infer(
enum_name: impl Into<String>,
variants: Vec<(String, Type)>,
variant_spans: &[Span],
) -> Result<Self, Diagnostic>
pub fn infer( enum_name: impl Into<String>, variants: Vec<(String, Type)>, variant_spans: &[Span], ) -> Result<Self, Diagnostic>
Attempts to create a new enum type by computing the common inner type through coercion.
Finds the common inner type among all variant types. If the enum has no
variants, the coerced inner type is Type::Union.
Returns an error if no common type can be found among the variants.
Sourcepub fn inner_value_type(&self) -> &Type
pub fn inner_value_type(&self) -> &Type
Gets the inner value type that all variants coerce to.
Trait Implementations§
Source§impl Coercible for EnumType
impl Coercible for EnumType
Source§fn is_coercible_to(&self, _: &Self) -> bool
fn is_coercible_to(&self, _: &Self) -> bool
Determines if the type is coercible to the target type.
Source§impl From<EnumType> for CompoundType
impl From<EnumType> for CompoundType
Source§impl From<EnumType> for CustomType
impl From<EnumType> for CustomType
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 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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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>
Converts
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>
Converts
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.