[][src]Trait eff::Effectful

pub trait Effectful {
type Output;
type Effect;
    fn poll(
        self: Pin<&mut Self>,
        cx: &Context
    ) -> Poll<Self::Output, Self::Effect>; fn handle<H, HC, Effect, I>(
        self,
        handler: H
    ) -> Handled<Self, H, HC, Effect, I>
    where
        Self: Sized,
        H: FnMut(HandlerArgument<Self::Output, Effect>) -> HC,
        Self::Effect: Subset<Effect, I>
, { ... }
fn embed<Target, Indices>(self) -> EmbedEffect<Self, Target, Indices>
    where
        Self: Sized
, { ... }
fn left<R>(self) -> Either<Self, R>
    where
        Self: Sized
, { ... }
fn right<L>(self) -> Either<L, Self>
    where
        Self: Sized
, { ... }
fn boxed<'a>(
        self
    ) -> Pin<Box<dyn Effectful<Output = Self::Output, Effect = Self::Effect> + 'a>>
    where
        Self: Sized + 'a
, { ... }
fn block_on(self) -> Self::Output
    where
        Self: Sized + Effectful<Effect = !>
, { ... } }

An effectful computation

Associated Types

type Output

The type of the final result

type Effect

The type of the effects this computation will produce

Loading content...

Required methods

fn poll(self: Pin<&mut Self>, cx: &Context) -> Poll<Self::Output, Self::Effect>

Resume the computation to a final value, registering the current task for wakeup if a handler starts handling an effect performed by the task

Return value

This function returns:

  • Poll::Done(v) with a result v if the computation completed successfully
  • Poll::Effect(e) with an effect e if the computation performed a computational effect
  • Poll::Pending if the computation is not ready to continue because a handler is handling an effect

Once a computation has completed, clients should not poll it again

When a computation performs an effect, poll returns Poll::Effect(e) with the effect e

When a handler decides to handle an effect, it will register interest in the result for the current task. In this case, poll returns Poll::NotReady until the task gets woken up with the outcome of the effect.

Panics

After the completion of the computation (poll returned Poll::Done), future calls to poll may panic or cause bad behavior. The Effectful trait does not provide any guarantees about the safety of calling poll after the task has finished.

Loading content...

Provided methods

fn handle<H, HC, Effect, I>(self, handler: H) -> Handled<Self, H, HC, Effect, I> where
    Self: Sized,
    H: FnMut(HandlerArgument<Self::Output, Effect>) -> HC,
    Self::Effect: Subset<Effect, I>, 

Takes a value handler and an effect handler and creates an effectful computation with the effects handled

fn embed<Target, Indices>(self) -> EmbedEffect<Self, Target, Indices> where
    Self: Sized

Creates an effectful computation whose effect is a superset of that of this one

fn left<R>(self) -> Either<Self, R> where
    Self: Sized

Combine this and the other computation with the same signature

fn right<L>(self) -> Either<L, Self> where
    Self: Sized

Combine this and the other computation with the same signature

fn boxed<'a>(
    self
) -> Pin<Box<dyn Effectful<Output = Self::Output, Effect = Self::Effect> + 'a>> where
    Self: Sized + 'a, 

Create a boxed computation

This function can be used to erase Self type

fn block_on(self) -> Self::Output where
    Self: Sized + Effectful<Effect = !>, 

Run the computation to completion on the current thread

This method blocks the current thread while waiting on the progress of the computation

The effect type of this computation must be an empty set (never type) since there is no handler

Loading content...

Implementations on Foreign Types

impl<C: ?Sized, '_> Effectful for Pin<&'_ mut C> where
    C: Effectful
[src]

type Output = C::Output

type Effect = C::Effect

fn handle<H, HC, Effect, I>(self, handler: H) -> Handled<Self, H, HC, Effect, I> where
    Self: Sized,
    H: FnMut(HandlerArgument<Self::Output, Effect>) -> HC,
    Self::Effect: Subset<Effect, I>, 
[src]

fn embed<Target, Indices>(self) -> EmbedEffect<Self, Target, Indices> where
    Self: Sized
[src]

fn left<R>(self) -> Either<Self, R> where
    Self: Sized
[src]

fn right<L>(self) -> Either<L, Self> where
    Self: Sized
[src]

fn boxed<'a>(
    self
) -> Pin<Box<dyn Effectful<Output = Self::Output, Effect = Self::Effect> + 'a>> where
    Self: Sized + 'a, 
[src]

fn block_on(self) -> Self::Output where
    Self: Sized + Effectful<Effect = !>, 
[src]

impl<C: ?Sized> Effectful for Pin<Box<C>> where
    C: Effectful
[src]

type Output = C::Output

type Effect = C::Effect

fn handle<H, HC, Effect, I>(self, handler: H) -> Handled<Self, H, HC, Effect, I> where
    Self: Sized,
    H: FnMut(HandlerArgument<Self::Output, Effect>) -> HC,
    Self::Effect: Subset<Effect, I>, 
[src]

fn embed<Target, Indices>(self) -> EmbedEffect<Self, Target, Indices> where
    Self: Sized
[src]

fn left<R>(self) -> Either<Self, R> where
    Self: Sized
[src]

fn right<L>(self) -> Either<L, Self> where
    Self: Sized
[src]

fn boxed<'a>(
    self
) -> Pin<Box<dyn Effectful<Output = Self::Output, Effect = Self::Effect> + 'a>> where
    Self: Sized + 'a, 
[src]

fn block_on(self) -> Self::Output where
    Self: Sized + Effectful<Effect = !>, 
[src]

Loading content...

Implementors

impl<C, Output, Effect, H, HC, HandledEffect, NewOutput, NewEffect, I> Effectful for Handled<C, H, HC, HandledEffect, I> where
    C: Effectful<Output = Output, Effect = Effect>,
    H: FnMut(HandlerArgument<Output, HandledEffect>) -> HC,
    HC: Effectful<Output = NewOutput, Effect = Either<Continue<Output>, NewEffect>>,
    Effect: Subset<HandledEffect, I, Remainder = NewEffect>, 
[src]

type Output = NewOutput

type Effect = NewEffect

fn handle<H, HC, Effect, I>(self, handler: H) -> Handled<Self, H, HC, Effect, I> where
    Self: Sized,
    H: FnMut(HandlerArgument<Self::Output, Effect>) -> HC,
    Self::Effect: Subset<Effect, I>, 
[src]

fn embed<Target, Indices>(self) -> EmbedEffect<Self, Target, Indices> where
    Self: Sized
[src]

fn left<R>(self) -> Either<Self, R> where
    Self: Sized
[src]

fn right<L>(self) -> Either<L, Self> where
    Self: Sized
[src]

fn boxed<'a>(
    self
) -> Pin<Box<dyn Effectful<Output = Self::Output, Effect = Self::Effect> + 'a>> where
    Self: Sized + 'a, 
[src]

fn block_on(self) -> Self::Output where
    Self: Sized + Effectful<Effect = !>, 
[src]

impl<C, Target, Indices> Effectful for EmbedEffect<C, Target, Indices> where
    C: Effectful,
    C::Effect: Embed<Target, Indices>, 
[src]

type Output = C::Output

type Effect = Target

fn handle<H, HC, Effect, I>(self, handler: H) -> Handled<Self, H, HC, Effect, I> where
    Self: Sized,
    H: FnMut(HandlerArgument<Self::Output, Effect>) -> HC,
    Self::Effect: Subset<Effect, I>, 
[src]

fn embed<Target, Indices>(self) -> EmbedEffect<Self, Target, Indices> where
    Self: Sized
[src]

fn left<R>(self) -> Either<Self, R> where
    Self: Sized
[src]

fn right<L>(self) -> Either<L, Self> where
    Self: Sized
[src]

fn boxed<'a>(
    self
) -> Pin<Box<dyn Effectful<Output = Self::Output, Effect = Self::Effect> + 'a>> where
    Self: Sized + 'a, 
[src]

fn block_on(self) -> Self::Output where
    Self: Sized + Effectful<Effect = !>, 
[src]

impl<Output, Effect, L, R> Effectful for Either<L, R> where
    L: Effectful<Output = Output, Effect = Effect>,
    R: Effectful<Output = Output, Effect = Effect>, 
[src]

type Output = Output

type Effect = Effect

fn handle<H, HC, Effect, I>(self, handler: H) -> Handled<Self, H, HC, Effect, I> where
    Self: Sized,
    H: FnMut(HandlerArgument<Self::Output, Effect>) -> HC,
    Self::Effect: Subset<Effect, I>, 
[src]

fn embed<Target, Indices>(self) -> EmbedEffect<Self, Target, Indices> where
    Self: Sized
[src]

fn left<R>(self) -> Either<Self, R> where
    Self: Sized
[src]

fn right<L>(self) -> Either<L, Self> where
    Self: Sized
[src]

fn boxed<'a>(
    self
) -> Pin<Box<dyn Effectful<Output = Self::Output, Effect = Self::Effect> + 'a>> where
    Self: Sized + 'a, 
[src]

fn block_on(self) -> Self::Output where
    Self: Sized + Effectful<Effect = !>, 
[src]

impl<T, F> Effectful for Lazy<F> where
    F: FnOnce() -> T, 
[src]

type Output = T

type Effect = !

fn poll(self: Pin<&mut Self>, _cx: &Context) -> Poll<Self::Output, Self::Effect>[src]

Execute the computation

Panics

Panics if the task is polled again after completion

fn handle<H, HC, Effect, I>(self, handler: H) -> Handled<Self, H, HC, Effect, I> where
    Self: Sized,
    H: FnMut(HandlerArgument<Self::Output, Effect>) -> HC,
    Self::Effect: Subset<Effect, I>, 
[src]

fn embed<Target, Indices>(self) -> EmbedEffect<Self, Target, Indices> where
    Self: Sized
[src]

fn left<R>(self) -> Either<Self, R> where
    Self: Sized
[src]

fn right<L>(self) -> Either<L, Self> where
    Self: Sized
[src]

fn boxed<'a>(
    self
) -> Pin<Box<dyn Effectful<Output = Self::Output, Effect = Self::Effect> + 'a>> where
    Self: Sized + 'a, 
[src]

fn block_on(self) -> Self::Output where
    Self: Sized + Effectful<Effect = !>, 
[src]

Loading content...