Struct bevy::reflect::TypeRegistration
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§
§impl TypeRegistration
impl TypeRegistration
pub fn data<T>(&self) -> Option<&T>where
T: TypeData,
pub fn data<T>(&self) -> Option<&T>where
T: TypeData,
Returns a reference to the value of type T
in this registration’s type
data.
Returns None
if no such value exists.
pub fn data_mut<T>(&mut self) -> Option<&mut T>where
T: TypeData,
pub fn data_mut<T>(&mut self) -> Option<&mut T>where
T: TypeData,
Returns a mutable reference to the value of type T
in this
registration’s type data.
Returns None
if no such value exists.
pub fn type_info(&self) -> &'static TypeInfo
pub fn type_info(&self) -> &'static TypeInfo
Returns a reference to the registration’s TypeInfo
Examples found in repository?
22 23 24 25 26 27 28 29 30 31 32 33
fn setup(type_registry: Res<AppTypeRegistry>) {
let type_registry = type_registry.read();
let registration = type_registry.get(TypeId::of::<MyType<u32>>()).unwrap();
info!(
"Registration for {} exists",
registration.type_info().type_path(),
);
// MyType<String> was not manually registered, so it does not exist
assert!(type_registry.get(TypeId::of::<MyType<String>>()).is_none());
}
pub fn insert<T>(&mut self, data: T)where
T: TypeData,
pub fn insert<T>(&mut self, data: T)where
T: TypeData,
Inserts an instance of T
into this registration’s type data.
If another instance of T
was previously inserted, it is replaced.
pub fn of<T>() -> TypeRegistration
pub fn of<T>() -> TypeRegistration
Creates type registration information for T
.
Trait Implementations§
§impl Clone for TypeRegistration
impl Clone for TypeRegistration
§fn clone(&self) -> TypeRegistration
fn clone(&self) -> TypeRegistration
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 TypeRegistration
impl !RefUnwindSafe for TypeRegistration
impl Send for TypeRegistration
impl Sync for TypeRegistration
impl Unpin for TypeRegistration
impl !UnwindSafe for TypeRegistration
Blanket Implementations§
§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
T
ShaderType
for self
. When used in AsBindGroup
derives, it is safe to assume that all images in self
exist.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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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
.§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
.§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.§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.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§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> ⓘ
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> ⓘ
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 more