pub struct Context<'a, E: Executor> {
pub executor: &'a E,
pub id: String,
/* 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
id: StringImplementations§
Source§impl<'a, E: Executor> Context<'a, E>
impl<'a, E: Executor> Context<'a, E>
Sourcepub async fn get_snapshot<D: DecodeOwned + ProjectionCursor>(
&self,
) -> Result<Option<D>>
pub async fn get_snapshot<D: DecodeOwned + ProjectionCursor>( &self, ) -> Result<Option<D>>
Retrieves a stored snapshot for the given ID.
Returns None if no snapshot exists.
Sourcepub async fn take_snapshot<D: Encode + ProjectionCursor>(
&self,
data: &D,
) -> Result<()>
pub async fn take_snapshot<D: Encode + ProjectionCursor>( &self, data: &D, ) -> Result<()>
Stores a snapshot for the given ID.
The snapshot cursor is extracted from the data to track the event position.
Sourcepub async fn aggregator<A: Aggregator>(&self) -> String
pub async fn aggregator<A: Aggregator>(&self) -> String
Returns the aggregate ID for a registered aggregator type.
§Panics
Panics if the aggregator type was not registered via Projection::aggregator.
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