Skip to main content

Program

Struct Program 

Source
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>

Source

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>

Source

pub fn new_send<Effs, F>( f: impl FnOnce(Yielder<'a, Effs>) -> F + Send + 'a, ) -> Program<'a, Effs, Result, Sendable, Effs, HNil>
where Effs: Effects<'a>, for<'r> <Coproduct<Start, Effs> as MapResume>::Output<'r>: Send + Sync, F: Future<Output = Result> + Send,

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,

Source

pub fn from_co(co: GenericCo<'a, Effs, R, L>) -> Self

Create a program from an existing coroutine.

Source§

impl<'a, Effs, R, L, Remaining, Handlers> Program<'a, Effs, R, L, Remaining, Handlers>
where Effs: Effects<'a>, L: Locality,

Source

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>
where HCons<F, HNil>: HandlersToEffects<'a, Effs, HandleIdx>, Remaining: CoproductSubsetter<<HCons<F, HNil> as HandlersToEffects<'a, Effs, HandleIdx>>::Effects, SubsetIdx>, Handlers: Add<HCons<F, HNil>>,

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.

Source

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,

Source

pub fn run_sync<Indices>(self) -> Result<R, Cancelled>
where Effs: HandleMut<'a, Effs, Handlers, Indices>,

Run the computation synchronously.

Source

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.

Source

pub async fn run<Indices>(self) -> Result<R, Cancelled>
where Effs: AsyncHandleMut<'a, Effs, Handlers, Indices>,

Run the computation asynchronously.

Source

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.

Auto Trait Implementations§

§

impl<'a, Effs, Result, L, Remaining, Handlers> Freeze for Program<'a, Effs, Result, L, Remaining, Handlers>
where Handlers: Freeze, <L as Locality>::PinBoxFuture<'a, Result>: Freeze,

§

impl<'a, Effs, Result, L, Remaining, Handlers> RefUnwindSafe for Program<'a, Effs, Result, L, Remaining, Handlers>
where Handlers: RefUnwindSafe, Remaining: RefUnwindSafe, <L as Locality>::PinBoxFuture<'a, Result>: RefUnwindSafe, Effs: RefUnwindSafe, <Effs as MapResume>::Output<'a>: RefUnwindSafe,

§

impl<'a, Effs, Result, L, Remaining, Handlers> Send for Program<'a, Effs, Result, L, Remaining, Handlers>
where Handlers: Send, Remaining: Send, <L as Locality>::PinBoxFuture<'a, Result>: Send, <Effs as MapResume>::Output<'a>: Send,

§

impl<'a, Effs, Result, L, Remaining, Handlers> Sync for Program<'a, Effs, Result, L, Remaining, Handlers>
where Handlers: Sync, Remaining: Sync, <L as Locality>::PinBoxFuture<'a, Result>: Sync, <Effs as MapResume>::Output<'a>: Sync,

§

impl<'a, Effs, Result, L, Remaining, Handlers> !Unpin for Program<'a, Effs, Result, L, Remaining, Handlers>

§

impl<'a, Effs, Result, L, Remaining, Handlers> !UnsafeUnpin for Program<'a, Effs, Result, L, Remaining, Handlers>

§

impl<'a, Effs, Result, L, Remaining, Handlers> UnwindSafe for Program<'a, Effs, Result, L, Remaining, Handlers>
where Handlers: UnwindSafe, Remaining: UnwindSafe, <L as Locality>::PinBoxFuture<'a, Result>: UnwindSafe, Effs: UnwindSafe, <Effs as MapResume>::Output<'a>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Choices> CoproductSubsetter<CNil, HNil> for Choices

Source§

type Remainder = Choices

Source§

fn subset( self, ) -> Result<CNil, <Choices as CoproductSubsetter<CNil, HNil>>::Remainder>

Extract a subset of the possible types in a coproduct (or get the remaining possibilities) Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U, I> LiftInto<U, I> for T
where U: LiftFrom<T, I>,

Source§

fn lift_into(self) -> U

Performs the indexed conversion.
Source§

impl<Source> Sculptor<HNil, HNil> for Source

Source§

type Remainder = Source

Source§

fn sculpt(self) -> (HNil, <Source as Sculptor<HNil, HNil>>::Remainder)

Consumes the current HList and returns an HList with the requested shape. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.