Trait Reflect
pub trait Reflect:
PartialReflect
+ DynamicTyped
+ Any {
// Required methods
fn into_any(self: Box<Self>) -> Box<dyn Any>;
fn as_any(&self) -> &(dyn Any + 'static);
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static);
fn into_reflect(self: Box<Self>) -> Box<dyn Reflect>;
fn as_reflect(&self) -> &(dyn Reflect + 'static);
fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static);
fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>>;
}Expand description
A core trait of bevy_reflect, used for downcasting to concrete types.
This is a subtrait of [PartialReflect],
meaning any type which implements Reflect implements PartialReflect by definition.
It’s recommended to use the derive macro rather than manually implementing this trait.
Doing so will automatically implement this trait, [PartialReflect], and many other useful traits for reflection,
including one of the appropriate subtraits: Struct, TupleStruct or Enum.
If you need to use this trait as a generic bound along with other reflection traits,
for your convenience, consider using Reflectable instead.
See the crate-level documentation to see how this trait can be used.
Required Methods§
fn into_any(self: Box<Self>) -> Box<dyn Any>
fn into_any(self: Box<Self>) -> Box<dyn Any>
Returns the value as a Box<dyn Any>.
For remote wrapper types, this will return the remote type instead.
fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Returns the value as a &dyn Any.
For remote wrapper types, this will return the remote type instead.
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Returns the value as a &mut dyn Any.
For remote wrapper types, this will return the remote type instead.
fn into_reflect(self: Box<Self>) -> Box<dyn Reflect>
fn into_reflect(self: Box<Self>) -> Box<dyn Reflect>
Casts this type to a boxed, fully-reflected value.
fn as_reflect(&self) -> &(dyn Reflect + 'static)
fn as_reflect(&self) -> &(dyn Reflect + 'static)
Casts this type to a fully-reflected value.
fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)
fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)
Casts this type to a mutable, fully-reflected value.
Implementations§
§impl dyn Reflect
impl dyn Reflect
pub fn downcast<T>(self: Box<dyn Reflect>) -> Result<Box<T>, Box<dyn Reflect>>where
T: Any,
pub fn downcast<T>(self: Box<dyn Reflect>) -> Result<Box<T>, Box<dyn Reflect>>where
T: Any,
Downcasts the value to type T, consuming the trait object.
If the underlying value is not of type T, returns Err(self).
For remote types, T should be the type itself rather than the wrapper type.
pub fn take<T>(self: Box<dyn Reflect>) -> Result<T, Box<dyn Reflect>>where
T: Any,
pub fn take<T>(self: Box<dyn Reflect>) -> Result<T, Box<dyn Reflect>>where
T: Any,
Downcasts the value to type T, unboxing and consuming the trait object.
If the underlying value is not of type T, returns Err(self).
For remote types, T should be the type itself rather than the wrapper type.
pub fn is<T>(&self) -> boolwhere
T: Any,
pub fn is<T>(&self) -> boolwhere
T: Any,
Returns true if the underlying value is of type T, or false
otherwise.
The underlying value is the concrete type that is stored in this dyn object;
it can be downcast to. In the case that this underlying value “represents”
a different type, like the Dynamic*** types do, you can call represents
to determine what type they represent. Represented types cannot be downcast
to, but you can use FromReflect to create a value of the represented type from them.
For remote types, T should be the type itself rather than the wrapper type.
pub fn downcast_ref<T>(&self) -> Option<&T>where
T: Any,
pub fn downcast_ref<T>(&self) -> Option<&T>where
T: Any,
Downcasts the value to type T by reference.
If the underlying value is not of type T, returns None.
For remote types, T should be the type itself rather than the wrapper type.
pub fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: Any,
pub fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: Any,
Downcasts the value to type T by mutable reference.
If the underlying value is not of type T, returns None.
For remote types, T should be the type itself rather than the wrapper type.