pub enum TypeInfo {
Struct(StructInfo),
TupleStruct(TupleStructInfo),
Tuple(TupleInfo),
List(ListInfo),
Array(ArrayInfo),
Map(MapInfo),
Set(SetInfo),
Enum(EnumInfo),
Opaque(OpaqueInfo),
}
Expand description
Compile-time type information for various reflected types.
Generally, for any given type, this value can be retrieved in one of four ways:
Typed::type_info
DynamicTyped::reflect_type_info
PartialReflect::get_represented_type_info
TypeRegistry::get_type_info
Each return a static reference to TypeInfo
, but they all have their own use cases.
For example, if you know the type at compile time, Typed::type_info
is probably
the simplest. If you have a dyn Reflect
you can use DynamicTyped::reflect_type_info
.
If all you have is a dyn PartialReflect
, you’ll probably want PartialReflect::get_represented_type_info
.
Lastly, if all you have is a TypeId
or type path, you will need to go through
TypeRegistry::get_type_info
.
You may also opt to use TypeRegistry::get_type_info
in place of the other methods simply because
it can be more performant. This is because those other methods may require attaining a lock on
the static TypeInfo
, while the registry simply checks a map.
Variants§
Struct(StructInfo)
TupleStruct(TupleStructInfo)
Tuple(TupleInfo)
List(ListInfo)
Array(ArrayInfo)
Map(MapInfo)
Set(SetInfo)
Enum(EnumInfo)
Opaque(OpaqueInfo)
Implementations§
Source§impl TypeInfo
impl TypeInfo
Sourcepub fn type_path_table(&self) -> &TypePathTable
pub fn type_path_table(&self) -> &TypePathTable
A representation of the type path of the underlying type.
Provides dynamic access to all methods on TypePath
.
Sourcepub fn type_path(&self) -> &'static str
pub fn type_path(&self) -> &'static str
The stable, full type path of the underlying type.
Use type_path_table
if you need access to the other methods on TypePath
.
Sourcepub fn kind(&self) -> ReflectKind
pub fn kind(&self) -> ReflectKind
Returns the kind of this TypeInfo
.
Source§impl TypeInfo
impl TypeInfo
Conversion convenience methods for TypeInfo
.
Sourcepub fn as_struct(&self) -> Result<&StructInfo, TypeInfoError>
pub fn as_struct(&self) -> Result<&StructInfo, TypeInfoError>
Attempts a cast to StructInfo
.
Returns an error if self
is not TypeInfo::Struct
.
Sourcepub fn as_tuple_struct(&self) -> Result<&TupleStructInfo, TypeInfoError>
pub fn as_tuple_struct(&self) -> Result<&TupleStructInfo, TypeInfoError>
Attempts a cast to TupleStructInfo
.
Returns an error if self
is not TypeInfo::TupleStruct
.
Sourcepub fn as_tuple(&self) -> Result<&TupleInfo, TypeInfoError>
pub fn as_tuple(&self) -> Result<&TupleInfo, TypeInfoError>
Attempts a cast to TupleInfo
.
Returns an error if self
is not TypeInfo::Tuple
.
Sourcepub fn as_list(&self) -> Result<&ListInfo, TypeInfoError>
pub fn as_list(&self) -> Result<&ListInfo, TypeInfoError>
Attempts a cast to ListInfo
.
Returns an error if self
is not TypeInfo::List
.
Sourcepub fn as_array(&self) -> Result<&ArrayInfo, TypeInfoError>
pub fn as_array(&self) -> Result<&ArrayInfo, TypeInfoError>
Attempts a cast to ArrayInfo
.
Returns an error if self
is not TypeInfo::Array
.
Sourcepub fn as_map(&self) -> Result<&MapInfo, TypeInfoError>
pub fn as_map(&self) -> Result<&MapInfo, TypeInfoError>
Attempts a cast to MapInfo
.
Returns an error if self
is not TypeInfo::Map
.
Sourcepub fn as_enum(&self) -> Result<&EnumInfo, TypeInfoError>
pub fn as_enum(&self) -> Result<&EnumInfo, TypeInfoError>
Attempts a cast to EnumInfo
.
Returns an error if self
is not TypeInfo::Enum
.
Sourcepub fn as_opaque(&self) -> Result<&OpaqueInfo, TypeInfoError>
pub fn as_opaque(&self) -> Result<&OpaqueInfo, TypeInfoError>
Attempts a cast to OpaqueInfo
.
Returns an error if self
is not TypeInfo::Opaque
.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TypeInfo
impl !RefUnwindSafe for TypeInfo
impl Send for TypeInfo
impl Sync for TypeInfo
impl Unpin for TypeInfo
impl !UnwindSafe for TypeInfo
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.