Struct bevy_reflect::attributes::CustomAttributes
source · pub struct CustomAttributes { /* private fields */ }
Expand description
A collection of custom attributes for a type, field, or variant.
These attributes can be created with the Reflect
derive macro.
Attributes are stored by their TypeId
.
Because of this, there can only be one attribute per type.
§Example
use core::ops::RangeInclusive;
#[derive(Reflect)]
struct Slider {
#[reflect(@RangeInclusive::<f32>::new(0.0, 1.0))]
value: f32
}
let TypeInfo::Struct(info) = <Slider as Typed>::type_info() else {
panic!("expected struct info");
};
let range = info.field("value").unwrap().get_attribute::<RangeInclusive<f32>>().unwrap();
assert_eq!(0.0..=1.0, *range);
Implementations§
source§impl CustomAttributes
impl CustomAttributes
sourcepub fn with_attribute<T: Reflect>(self, value: T) -> Self
pub fn with_attribute<T: Reflect>(self, value: T) -> Self
Inserts a custom attribute into the collection.
Note that this will overwrite any existing attribute of the same type.
sourcepub fn contains<T: Reflect>(&self) -> bool
pub fn contains<T: Reflect>(&self) -> bool
Returns true
if this collection contains a custom attribute of the specified type.
sourcepub fn contains_by_id(&self, id: TypeId) -> bool
pub fn contains_by_id(&self, id: TypeId) -> bool
Returns true
if this collection contains a custom attribute with the specified TypeId
.
sourcepub fn get_by_id(&self, id: TypeId) -> Option<&dyn Reflect>
pub fn get_by_id(&self, id: TypeId) -> Option<&dyn Reflect>
Gets a custom attribute by its TypeId
.
sourcepub fn iter(&self) -> impl ExactSizeIterator<Item = (&TypeId, &dyn Reflect)>
pub fn iter(&self) -> impl ExactSizeIterator<Item = (&TypeId, &dyn Reflect)>
Returns an iterator over all custom attributes.
Trait Implementations§
source§impl Debug for CustomAttributes
impl Debug for CustomAttributes
source§impl Default for CustomAttributes
impl Default for CustomAttributes
source§fn default() -> CustomAttributes
fn default() -> CustomAttributes
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for CustomAttributes
impl !RefUnwindSafe for CustomAttributes
impl Send for CustomAttributes
impl Sync for CustomAttributes
impl Unpin for CustomAttributes
impl !UnwindSafe for CustomAttributes
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
Mutably borrows from an owned value. Read more
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>
Convert
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>
Convert
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)
Convert
&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)
Convert
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.