pub struct TypeRegistration { /* private fields */ }
Expand description
Runtime storage for type metadata, registered into the TypeRegistry
.
An instance of TypeRegistration
can be created using the TypeRegistration::of
method,
but is more often automatically generated using #[derive(Reflect)]
which itself generates
an implementation of the GetTypeRegistration
trait.
Along with the type’s TypeInfo
,
this struct also contains a type’s registered TypeData
.
See the crate-level documentation for more information on type registration.
§Example
let mut registration = TypeRegistration::of::<Option<String>>();
assert_eq!("core::option::Option<alloc::string::String>", registration.type_info().type_path());
assert_eq!("Option<String>", registration.type_info().type_path_table().short_path());
registration.insert::<ReflectDefault>(FromType::<Option<String>>::from_type());
assert!(registration.data::<ReflectDefault>().is_some())
Implementations§
Source§impl TypeRegistration
impl TypeRegistration
Sourcepub fn of<T: Reflect + Typed + TypePath>() -> Self
pub fn of<T: Reflect + Typed + TypePath>() -> Self
Creates type registration information for T
.
Sourcepub fn type_info(&self) -> &'static TypeInfo
pub fn type_info(&self) -> &'static TypeInfo
Returns a reference to the registration’s TypeInfo
Sourcepub fn insert<T: TypeData>(&mut self, data: T)
pub fn insert<T: TypeData>(&mut self, data: T)
Inserts an instance of T
into this registration’s type data.
If another instance of T
was previously inserted, it is replaced.
Sourcepub fn data<T: TypeData>(&self) -> Option<&T>
pub fn data<T: TypeData>(&self) -> Option<&T>
Returns a reference to the value of type T
in this registration’s
type data.
Returns None
if no such value exists.
For a dynamic version of this method, see data_by_id
.
Sourcepub fn data_by_id(&self, type_id: TypeId) -> Option<&dyn TypeData>
pub fn data_by_id(&self, type_id: TypeId) -> Option<&dyn TypeData>
Sourcepub fn data_mut<T: TypeData>(&mut self) -> Option<&mut T>
pub fn data_mut<T: TypeData>(&mut self) -> Option<&mut T>
Returns a mutable reference to the value of type T
in this registration’s
type data.
Returns None
if no such value exists.
For a dynamic version of this method, see data_mut_by_id
.
Sourcepub fn data_mut_by_id(&mut self, type_id: TypeId) -> Option<&mut dyn TypeData>
pub fn data_mut_by_id(&mut self, type_id: TypeId) -> Option<&mut dyn TypeData>
Sourcepub fn contains<T: TypeData>(&self) -> bool
pub fn contains<T: TypeData>(&self) -> bool
Returns true if this registration contains the given type data.
For a dynamic version of this method, see contains_by_id
.
Sourcepub fn contains_by_id(&self, type_id: TypeId) -> bool
pub fn contains_by_id(&self, type_id: TypeId) -> bool
Sourcepub fn iter(&self) -> impl ExactSizeIterator<Item = (TypeId, &dyn TypeData)>
pub fn iter(&self) -> impl ExactSizeIterator<Item = (TypeId, &dyn TypeData)>
Trait Implementations§
Source§impl Clone for TypeRegistration
impl Clone for TypeRegistration
Auto Trait Implementations§
impl Freeze for TypeRegistration
impl !RefUnwindSafe for TypeRegistration
impl Send for TypeRegistration
impl Sync for TypeRegistration
impl Unpin for TypeRegistration
impl !UnwindSafe for TypeRegistration
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.