pub struct Program<'a, Effs: Effects<'a>, Result, L: Locality, Remaining, Handlers> { /* private fields */ }Expand description
A computation with incrementally attached effect handlers.
Handlers are added one at a time via handle,
or in bulk via handle_all.
Once all effects are handled (Remaining = CNil), the computation
can be executed via run or run_sync.
Implementations§
Source§impl<'a, Result> Program<'a, CNil, Result, Local, CNil, HNil>
impl<'a, Result> Program<'a, CNil, Result, Local, CNil, HNil>
Sourcepub fn new<Effs, F>(
f: impl FnOnce(Yielder<'a, Effs>) -> F + 'a,
) -> Program<'a, Effs, Result, Local, Effs, HNil>where
Effs: Effects<'a>,
F: Future<Output = Result>,
pub fn new<Effs, F>(
f: impl FnOnce(Yielder<'a, Effs>) -> F + 'a,
) -> Program<'a, Effs, Result, Local, Effs, HNil>where
Effs: Effects<'a>,
F: Future<Output = Result>,
Create a new program from a computation closure.
The effect set can be inferred from the closure parameter annotation, or specified explicitly via turbofish:
// With closure annotation:
Program::new(|y: Yielder<'_, Effs>| async move { ... })
// With turbofish:
Program::new::<Effects![Counter, Ask], _>(|y| async move { ... })Source§impl<'a, Result> Program<'a, CNil, Result, Sendable, CNil, HNil>
impl<'a, Result> Program<'a, CNil, Result, Sendable, CNil, HNil>
Sourcepub fn new_send<Effs, F>(
f: impl FnOnce(Yielder<'a, Effs>) -> F + Send + 'a,
) -> Program<'a, Effs, Result, Sendable, Effs, HNil>
pub fn new_send<Effs, F>( f: impl FnOnce(Yielder<'a, Effs>) -> F + Send + 'a, ) -> Program<'a, Effs, Result, Sendable, Effs, HNil>
Create a new Send-able program from a computation closure.
The effect set can be inferred from the closure parameter annotation, or specified explicitly via turbofish:
// With closure annotation:
Program::new_send(|y: Yielder<'_, Effs>| async move { ... })
// With turbofish:
Program::new_send::<Effects![Counter, Ask], _>(|y| async move { ... })Source§impl<'a, Effs, R, L> Program<'a, Effs, R, L, Effs, HNil>where
Effs: Effects<'a>,
L: Locality,
impl<'a, Effs, R, L> Program<'a, Effs, R, L, Effs, HNil>where
Effs: Effects<'a>,
L: Locality,
Source§impl<'a, Effs, R, L, Remaining, Handlers> Program<'a, Effs, R, L, Remaining, Handlers>where
Effs: Effects<'a>,
L: Locality,
impl<'a, Effs, R, L, Remaining, Handlers> Program<'a, Effs, R, L, Remaining, Handlers>where
Effs: Effects<'a>,
L: Locality,
Sourcepub fn handle<F, HandleIdx, SubsetIdx>(
self,
handler: F,
) -> Program<'a, Effs, R, L, <Remaining as CoproductSubsetter<<HCons<F, HNil> as HandlersToEffects<'a, Effs, HandleIdx>>::Effects, SubsetIdx>>::Remainder, <Handlers as Add<HCons<F, HNil>>>::Output>
pub fn handle<F, HandleIdx, SubsetIdx>( self, handler: F, ) -> Program<'a, Effs, R, L, <Remaining as CoproductSubsetter<<HCons<F, HNil> as HandlersToEffects<'a, Effs, HandleIdx>>::Effects, SubsetIdx>>::Remainder, <Handlers as Add<HCons<F, HNil>>>::Output>
Attach a handler for an unhandled effect.
Handlers can be attached in any order — the effect type is
inferred from the closure signature and removed from the
remaining set via CoproductSubsetter.
Sourcepub fn handle_all<H, HandleIdx, SubsetIdx>(
self,
handlers: H,
) -> Program<'a, Effs, R, L, <Remaining as CoproductSubsetter<<H as HandlersToEffects<'a, Effs, HandleIdx>>::Effects, SubsetIdx>>::Remainder, <Handlers as Add<H>>::Output>where
H: HandlersToEffects<'a, Effs, HandleIdx>,
Remaining: CoproductSubsetter<H::Effects, SubsetIdx>,
Handlers: Add<H>,
pub fn handle_all<H, HandleIdx, SubsetIdx>(
self,
handlers: H,
) -> Program<'a, Effs, R, L, <Remaining as CoproductSubsetter<<H as HandlersToEffects<'a, Effs, HandleIdx>>::Effects, SubsetIdx>>::Remainder, <Handlers as Add<H>>::Output>where
H: HandlersToEffects<'a, Effs, HandleIdx>,
Remaining: CoproductSubsetter<H::Effects, SubsetIdx>,
Handlers: Add<H>,
Attach multiple handlers at once from an HList.
The handlers can be for any subset of the remaining effects,
in any order. The effect types are inferred from the handler
closure signatures, and CoproductSubsetter removes those
effects from the Remaining set.
Source§impl<'a, Effs, R, L, Handlers> Program<'a, Effs, R, L, CNil, Handlers>where
Effs: Effects<'a>,
L: Locality,
impl<'a, Effs, R, L, Handlers> Program<'a, Effs, R, L, CNil, Handlers>where
Effs: Effects<'a>,
L: Locality,
Sourcepub fn run_sync<Indices>(self) -> Result<R, Cancelled>where
Effs: HandleMut<'a, Effs, Handlers, Indices>,
pub fn run_sync<Indices>(self) -> Result<R, Cancelled>where
Effs: HandleMut<'a, Effs, Handlers, Indices>,
Run the computation synchronously.
Sourcepub fn run_sync_stateful<S, Indices>(
self,
state: &mut S,
) -> Result<R, Cancelled>where
Effs: HandleWith<'a, Effs, Handlers, S, Indices>,
pub fn run_sync_stateful<S, Indices>(
self,
state: &mut S,
) -> Result<R, Cancelled>where
Effs: HandleWith<'a, Effs, Handlers, S, Indices>,
Run the computation synchronously with shared state.
Sourcepub async fn run<Indices>(self) -> Result<R, Cancelled>where
Effs: AsyncHandleMut<'a, Effs, Handlers, Indices>,
pub async fn run<Indices>(self) -> Result<R, Cancelled>where
Effs: AsyncHandleMut<'a, Effs, Handlers, Indices>,
Run the computation asynchronously.
Sourcepub async fn run_stateful<S, Indices>(
self,
state: &mut S,
) -> Result<R, Cancelled>where
Effs: AsyncHandleWith<'a, Effs, Handlers, S, Indices>,
pub async fn run_stateful<S, Indices>(
self,
state: &mut S,
) -> Result<R, Cancelled>where
Effs: AsyncHandleWith<'a, Effs, Handlers, S, Indices>,
Run the computation asynchronously with shared state.