pub struct Context<'a, E: Executor> {
pub executor: &'a E,
/* private fields */
}Expand description
Handler context providing access to executor and shared data.
Context wraps an RwContext for type-safe
data storage and provides access to the executor for database operations.
§Example
ⓘ
#[evento::handler]
async fn my_handler<E: Executor>(
event: Event<MyEventData>,
action: Action<'_, MyView, E>,
) -> anyhow::Result<()> {
if let Action::Handle(ctx) = action {
// Access shared data
let config: Data<AppConfig> = ctx.extract();
// Use executor for queries
let events = ctx.executor.read(...).await?;
}
Ok(())
}Fields§
§executor: &'a EReference to the executor for database operations
Methods from Deref<Target = RwContext>§
Sourcepub fn insert<T: Send + Sync + 'static>(&self, val: T) -> Option<T>
pub fn insert<T: Send + Sync + 'static>(&self, val: T) -> Option<T>
Insert an item into the map.
If an item of this type was already stored, it will be replaced and returned.
Sourcepub fn extract<T: Clone + 'static>(&self) -> T
pub fn extract<T: Clone + 'static>(&self) -> T
Get a clone of an item of a given type, panics if not found.
Trait Implementations§
Auto Trait Implementations§
impl<'a, E> Freeze for Context<'a, E>
impl<'a, E> RefUnwindSafe for Context<'a, E>where
E: RefUnwindSafe,
impl<'a, E> Send for Context<'a, E>
impl<'a, E> Sync for Context<'a, E>
impl<'a, E> Unpin for Context<'a, E>
impl<'a, E> UnwindSafe for Context<'a, E>where
E: RefUnwindSafe,
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