pub enum VariantInfo {
Struct(StructVariantInfo),
Tuple(TupleVariantInfo),
Unit(UnitVariantInfo),
}
Expand description
A container for compile-time enum variant info.
Variants§
Struct(StructVariantInfo)
Struct enums take the form:
enum MyEnum {
A {
foo: usize
}
}
Tuple(TupleVariantInfo)
Tuple enums take the form:
enum MyEnum {
A(usize)
}
Unit(UnitVariantInfo)
Unit enums take the form:
enum MyEnum {
A
}
Implementations§
Source§impl VariantInfo
impl VariantInfo
pub fn name(&self) -> &'static str
Sourcepub fn variant_type(&self) -> VariantType
pub fn variant_type(&self) -> VariantType
Returns the type of this variant.
Sourcepub fn custom_attributes(&self) -> &CustomAttributes
pub fn custom_attributes(&self) -> &CustomAttributes
Returns the custom attributes for this variant.
Sourcepub fn get_attribute<T: Reflect>(&self) -> Option<&T>
pub fn get_attribute<T: Reflect>(&self) -> Option<&T>
Gets a custom attribute by type.
For dynamically accessing an attribute, see get_attribute_by_id
.
Sourcepub fn get_attribute_by_id(&self, id: TypeId) -> Option<&dyn Reflect>
pub fn get_attribute_by_id(&self, id: TypeId) -> Option<&dyn Reflect>
Gets a custom attribute by its TypeId
.
This is the dynamic equivalent of get_attribute
.
Sourcepub fn has_attribute<T: Reflect>(&self) -> bool
pub fn has_attribute<T: Reflect>(&self) -> bool
Returns true
if this variant has a custom attribute of the specified type.
For dynamically checking if an attribute exists, see has_attribute_by_id
.
Sourcepub fn has_attribute_by_id(&self, id: TypeId) -> bool
pub fn has_attribute_by_id(&self, id: TypeId) -> bool
Returns true
if this variant has a custom attribute with the specified TypeId
.
This is the dynamic equivalent of has_attribute
Source§impl VariantInfo
impl VariantInfo
Conversion convenience methods for VariantInfo
.
Sourcepub fn as_struct_variant(&self) -> Result<&StructVariantInfo, VariantInfoError>
pub fn as_struct_variant(&self) -> Result<&StructVariantInfo, VariantInfoError>
Attempts a cast to StructVariantInfo
.
Returns an error if self
is not VariantInfo::Struct
.
Sourcepub fn as_tuple_variant(&self) -> Result<&TupleVariantInfo, VariantInfoError>
pub fn as_tuple_variant(&self) -> Result<&TupleVariantInfo, VariantInfoError>
Attempts a cast to TupleVariantInfo
.
Returns an error if self
is not VariantInfo::Tuple
.
Sourcepub fn as_unit_variant(&self) -> Result<&UnitVariantInfo, VariantInfoError>
pub fn as_unit_variant(&self) -> Result<&UnitVariantInfo, VariantInfoError>
Attempts a cast to UnitVariantInfo
.
Returns an error if self
is not VariantInfo::Unit
.
Trait Implementations§
Source§impl Clone for VariantInfo
impl Clone for VariantInfo
Source§fn clone(&self) -> VariantInfo
fn clone(&self) -> VariantInfo
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl Freeze for VariantInfo
impl !RefUnwindSafe for VariantInfo
impl Send for VariantInfo
impl Sync for VariantInfo
impl Unpin for VariantInfo
impl !UnwindSafe for VariantInfo
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,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.