pub struct TypedContext<'a, E: ?Sized> { /* private fields */ }
Expand description
Implementations§
Source§impl<'a, Entry> TypedContext<'a, Entry>where
Entry: 'static,
impl<'a, Entry> TypedContext<'a, Entry>where
Entry: 'static,
Sourcepub fn add_trait<Trait>(&mut self) -> &mut Self
pub fn add_trait<Trait>(&mut self) -> &mut Self
Add a trait to the type map. This method is idempotent, so adding a trait multiple times will only register it once.
By default, every type is associated with the TraitMapEntry trait.
§Examples
impl TraitMapEntry for MyStruct {
fn on_create<'a>(&mut self, context: Context<'a>) {
context
.downcast::<Self>()
.add_trait::<dyn ExampleTrait>()
.add_trait::<dyn ExampleTraitTwo>();
}
}
Sourcepub fn remove_trait<Trait>(&mut self) -> &mut Self
pub fn remove_trait<Trait>(&mut self) -> &mut Self
Remove a trait from the type map. This method is idempotent, so removing a trait multiple times is a no-op.
By default, every type is associated with the TraitMapEntry trait.
As such, this trait cannot be removed from an entry.
Trying to call .remove_trait::<dyn TraitMapEntry>()
is a no-op.
§Examples
impl TraitMapEntry for MyStruct {
// ...
fn on_update<'a>(&mut self, context: Context<'a>) {
context
.downcast::<Self>()
.remove_trait::<dyn ExampleTrait>()
.remove_trait::<dyn ExampleTraitTwo>();
}
}
Sourcepub fn has_trait<Trait>(&self) -> bool
pub fn has_trait<Trait>(&self) -> bool
Test if the trait is registered with the type map.
§Examples
impl TraitMapEntry for MyStruct {
// ...
fn on_update<'a>(&mut self, context: Context<'a>) {
let mut context = context.downcast::<Self>();
if !context.has_trait::<dyn ExampleTrait>() {
context.add_trait<dyn ExampleTrait>();
}
}
}
Trait Implementations§
Auto Trait Implementations§
impl<'a, E> Freeze for TypedContext<'a, E>where
E: ?Sized,
impl<'a, E> !RefUnwindSafe for TypedContext<'a, E>
impl<'a, E> !Send for TypedContext<'a, E>
impl<'a, E> !Sync for TypedContext<'a, E>
impl<'a, E> Unpin for TypedContext<'a, E>where
E: ?Sized,
impl<'a, E> !UnwindSafe for TypedContext<'a, E>
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