pub trait Reflect:
PartialReflect
+ DynamicTyped
+ Any {
// Required methods
fn into_any(self: Box<Self>) -> Box<dyn Any>;
fn as_any(&self) -> &dyn Any;
fn as_any_mut(&mut self) -> &mut dyn Any;
fn into_reflect(self: Box<Self>) -> Box<dyn Reflect>;
fn as_reflect(&self) -> &dyn Reflect;
fn as_reflect_mut(&mut self) -> &mut dyn Reflect;
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§
sourcefn 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.
sourcefn as_any(&self) -> &dyn Any
fn as_any(&self) -> &dyn Any
Returns the value as a &dyn Any
.
For remote wrapper types, this will return the remote type instead.
sourcefn as_any_mut(&mut self) -> &mut dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
Returns the value as a &mut dyn Any
.
For remote wrapper types, this will return the remote type instead.
sourcefn 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.
sourcefn as_reflect(&self) -> &dyn Reflect
fn as_reflect(&self) -> &dyn Reflect
Casts this type to a fully-reflected value.
sourcefn as_reflect_mut(&mut self) -> &mut dyn Reflect
fn as_reflect_mut(&mut self) -> &mut dyn Reflect
Casts this type to a mutable, fully-reflected value.
Implementations§
source§impl dyn Reflect
impl dyn Reflect
sourcepub fn downcast<T: Any>(
self: Box<dyn Reflect>,
) -> Result<Box<T>, Box<dyn Reflect>>
pub fn downcast<T: Any>( self: Box<dyn Reflect>, ) -> Result<Box<T>, Box<dyn Reflect>>
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.
sourcepub fn take<T: Any>(self: Box<dyn Reflect>) -> Result<T, Box<dyn Reflect>>
pub fn take<T: Any>(self: Box<dyn Reflect>) -> Result<T, Box<dyn Reflect>>
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.
sourcepub fn is<T: Any>(&self) -> bool
pub fn is<T: Any>(&self) -> bool
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 downcasted 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 downcasted
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.
sourcepub fn downcast_ref<T: Any>(&self) -> Option<&T>
pub fn downcast_ref<T: Any>(&self) -> Option<&T>
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.
sourcepub fn downcast_mut<T: Any>(&mut self) -> Option<&mut T>
pub fn downcast_mut<T: Any>(&mut self) -> Option<&mut T>
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.