pub struct Context<'a> { /* private fields */ }
Expand description
Stores type information about an entry inside of a TraitMap.
Must be cast to a TypedContext using the .downcast()
or .try_downcast()
methods for adding or removing traits from the map.
Implementations§
Source§impl<'a> Context<'a>
impl<'a> Context<'a>
Sourcepub fn downcast<T>(self) -> TypedContext<'a, T>where
T: 'static,
pub fn downcast<T>(self) -> TypedContext<'a, T>where
T: 'static,
Downcast into the concrete TypedContext.
§Panics
This method panics if the type parameter T
does not match the concrete type.
§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 try_downcast<T>(self) -> Result<TypedContext<'a, T>, Self>where
T: 'static,
pub fn try_downcast<T>(self) -> Result<TypedContext<'a, T>, Self>where
T: 'static,
Try to downcast into a concrete TypedContext.
§Errors
Returns None
if the type parameter T
does not match the concrete type.
§Examples
impl TraitMapEntry for MyStruct {
fn on_create<'a>(&mut self, context: Context<'a>) {
if let Some(context) = context.try_downcast::<Self>() {
context
.add_trait::<dyn ExampleTrait>()
.add_trait::<dyn ExampleTraitTwo>();
}
}
}
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Context<'a>
impl<'a> !RefUnwindSafe for Context<'a>
impl<'a> !Send for Context<'a>
impl<'a> !Sync for Context<'a>
impl<'a> Unpin for Context<'a>
impl<'a> !UnwindSafe for Context<'a>
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