Crate metatype[−][src]
Expand description
Helper methods to determine whether a type is TraitObject
, Slice
or
Concrete
, and work with them respectively.
Examples
assert_eq!(usize::METATYPE, MetaType::Concrete); assert_eq!(any::Any::METATYPE, MetaType::TraitObject); assert_eq!(<[u8]>::METATYPE, MetaType::Slice); let a: Box<usize> = Box::new(123); assert_eq!(Type::meta_type(&*a), MetaType::Concrete); let a: Box<dyn any::Any> = a; assert_eq!(Type::meta_type(&*a), MetaType::TraitObject); let a = [123,456]; assert_eq!(Type::meta_type(&a), MetaType::Concrete); let a: &[i32] = &a; assert_eq!(Type::meta_type(a), MetaType::Slice); let a: Box<dyn any::Any> = Box::new(123); let meta: TraitObject = type_coerce(Type::meta(&*a)); println!("vtable: {:?}", meta.vtable);
Note
This currently requires Rust nightly for the raw
, specialization
and
arbitrary_self_types
features.
Structs
Meta data for a concrete, sized type
Meta data for a slice
Meta data for a trait object
Enums
Meta type of a type
Traits
Implemented on all types, it provides helper methods to determine whether a type is TraitObject
, Slice
or Concrete
, and work with them respectively.
Functions
Convert from one type parameter to another, where they are the same type.
Returns None
if the types differ.
Convert from one type parameter to another, where they are the same type. Panics with an explanatory message if the types differ.
Gets an identifier which is globally unique to the specified type. This function will return the same value for a type regardless of whichever crate it is invoked in.