Skip to main content

Effect

Struct Effect 

Source
pub struct Effect<A, E, S> { /* private fields */ }
Expand description

A description of a program. A is the success value, E is the expected error, and S is the service environment required to run it.

Implementations§

Source§

impl<A, E, S> Effect<A, E, S>
where A: Send + Sync + 'static, E: Send + Sync + 'static, S: Send + Sync + 'static,

Source

pub fn succeed(value: A) -> Self
where A: Clone,

Source

pub fn fail(error: E) -> Self
where E: Clone,

Source

pub fn die(message: impl Into<String>) -> Self

Source

pub fn from_async<F, Fut>(f: F) -> Self
where F: Fn(Arc<S>, CancellationToken) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<A, Exit<E>>> + Send + 'static,

Build a program from services and a cancellation token. The function runs only when Effect::run is called.

Source

pub fn map<B, F>(&self, f: F) -> Effect<B, E, S>
where B: Send + Sync + 'static, F: Fn(A) -> B + Send + Sync + 'static,

Source

pub fn and_then<B, F>(&self, f: F) -> Effect<B, E, S>
where B: Send + Sync + 'static, F: Fn(A) -> Effect<B, E, S> + Send + Sync + 'static,

Source

pub fn catch_fail<F>(&self, f: F) -> Self
where F: Fn(E) -> Effect<A, E, S> + Send + Sync + 'static,

Handle an expected failure. Defects and interruption pass through.

Source

pub fn retry(&self, schedule: Schedule) -> Self
where E: Clone,

Retry expected failures. Interruption and defects are not retried.

Source

pub fn timeout(&self, duration: Duration) -> Self

Source

pub fn with_span(&self, name: impl Into<String>) -> Self

Source

pub fn zip_par<B>(&self, right: &Effect<B, E, S>) -> Effect<(A, B), E, S>
where B: Send + Sync + 'static,

Run left and right together. The first expected failure or defect cancels the sibling and waits for that sibling to finish.

Source

pub fn race(&self, other: &Self) -> Self

First success or failure wins. The other side is cancelled and awaited.

Source

pub fn bracket<B, F, R>(&self, release: R, body: F) -> Effect<B, E, S>
where A: Clone, B: Send + Sync + 'static, F: Fn(A) -> Effect<B, E, S> + Send + Sync + 'static, R: Fn(A) + Send + Sync + 'static,

Acquire a resource, use it, and release it on success, expected failure, and cancellation. Dropping the running future releases it too.

Source

pub fn provide<S2>(self, services: S) -> Effect<A, E, S2>
where S2: Send + Sync + 'static,

Replace the service environment. The resulting program no longer requires S; the caller supplies a different environment at the edge.

Source

pub async fn run( self, services: Arc<S>, ) -> (Result<A, Exit<E>>, Vec<TraceEvent>)

Trait Implementations§

Source§

impl<A, E, S> Clone for Effect<A, E, S>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<A, E, S> !RefUnwindSafe for Effect<A, E, S>

§

impl<A, E, S> !UnwindSafe for Effect<A, E, S>

§

impl<A, E, S> Freeze for Effect<A, E, S>
where Arc<dyn Fn(RunCtx<S>) -> Pin<Box<dyn Future<Output = Result<A, Exit<E>>> + Send>> + Send + Sync>: Freeze, PhantomData<fn() -> (A, E)>: Freeze,

§

impl<A, E, S> Send for Effect<A, E, S>
where Arc<dyn Fn(RunCtx<S>) -> Pin<Box<dyn Future<Output = Result<A, Exit<E>>> + Send>> + Send + Sync>: Send, PhantomData<fn() -> (A, E)>: Send,

§

impl<A, E, S> Sync for Effect<A, E, S>
where Arc<dyn Fn(RunCtx<S>) -> Pin<Box<dyn Future<Output = Result<A, Exit<E>>> + Send>> + Send + Sync>: Sync, PhantomData<fn() -> (A, E)>: Sync,

§

impl<A, E, S> Unpin for Effect<A, E, S>
where Arc<dyn Fn(RunCtx<S>) -> Pin<Box<dyn Future<Output = Result<A, Exit<E>>> + Send>> + Send + Sync>: Unpin, PhantomData<fn() -> (A, E)>: Unpin,

§

impl<A, E, S> UnsafeUnpin for Effect<A, E, S>
where Arc<dyn Fn(RunCtx<S>) -> Pin<Box<dyn Future<Output = Result<A, Exit<E>>> + Send>> + Send + Sync>: UnsafeUnpin, PhantomData<fn() -> (A, E)>: UnsafeUnpin,

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.