Effect

Struct Effect 

Source
pub struct Effect<R, E, A> { /* private fields */ }

Implementations§

Source§

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

Source

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

Creates an effect that succeeds with the given value.

Source

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

Creates an effect that fails with the given error.

Source

pub fn sync<F>(f: F) -> Self
where F: FnOnce() -> A + Send + Sync + 'static + Clone, A: Send,

Creates an effect from a function that returns a value.

Source

pub fn async_effect<F, Fut>(f: F) -> Self
where F: FnOnce() -> Fut + Send + Sync + 'static + Clone, Fut: Future<Output = A> + Send + 'static, A: Send,

Creates an effect from a future.

Source

pub fn sleep(duration: Duration) -> Self
where A: From<()>,

Creates an effect that sleeps for the specified duration.

Source

pub fn with_metric_increment(self, name: &str, labels: Vec<MetricLabel>) -> Self
where A: Send + Sync + 'static + Clone, E: Send + Sync + 'static + Clone,

Records a metric increment when this effect runs.

Source

pub fn with_metric_duration(self, name: &str, labels: Vec<MetricLabel>) -> Self
where A: Send + Sync + 'static + Clone, E: Send + Sync + 'static + Clone, R: 'static + Clone + Send + Sync,

Records duration of this effect in a histogram.

Source

pub fn timed(self, name: &str, labels: Vec<MetricLabel>) -> Self
where A: Send + Sync + 'static + Clone, E: Send + Sync + 'static + Clone, R: 'static + Clone + Send + Sync,

Source

pub fn access_async<F, Fut>(f: F) -> Self
where R: Send + Sync, F: FnOnce(EnvRef<R>, Ctx) -> Fut + Send + Sync + 'static + Clone, Fut: Future<Output = A> + Send + 'static, A: Send,

Creates an effect with access to the environment.

Source

pub fn provide(self, env: R) -> Effect<(), E, A>
where R: Clone + Send + Sync + 'static, E: Send + Sync + 'static, A: Send + Sync + 'static,

Provides the environment to the effect, eliminating the dependency R.

Source

pub fn done(exit: Exit<E, A>) -> Self
where E: Send + Sync + Clone, A: Send + Sync + Clone,

Creates an effect from an Exit value.

Source

pub fn map<B, F>(self, f: F) -> Effect<R, E, B>
where F: FnOnce(A) -> B + Send + Sync + 'static + Clone, B: Send + Sync + 'static + Clone, R: Clone + Send + Sync + 'static, E: Send + Sync + 'static, A: Send + Sync + 'static,

Source

pub fn map_error<E2, F>(self, f: F) -> Effect<R, E2, A>
where F: Fn(E) -> E2 + Send + Sync + 'static + Clone, R: Send + Sync + 'static, A: Send + Sync + 'static, E: Send + Sync + 'static, E2: Send + Sync + 'static,

Source

pub fn flat_map<B, F>(self, f: F) -> Effect<R, E, B>
where F: FnOnce(A) -> Effect<R, E, B> + Send + Sync + 'static + Clone, B: Send + 'static, R: Clone + Send + Sync + 'static, E: Send + Sync + 'static, A: Send + Sync,

Source

pub fn delay(self, duration: Duration) -> Effect<R, E, A>
where R: Clone + Send + Sync + 'static, E: Send + Sync + 'static, A: Send + Sync + 'static,

Delays the execution of this effect by the specified duration.

Source

pub fn trace(self, name: &'static str) -> Effect<R, E, A>
where R: Clone + Send + Sync + 'static, E: Send + Sync + 'static, A: Send + Sync + 'static,

Wraps the effect execution in a tracing span with the given name.

Source

pub fn on_interrupt<F, R2, E2, X>(self, cleanup: F) -> Effect<R, E, A>
where F: Fn() -> Effect<R2, E2, X> + Send + Sync + 'static + Clone, R2: From<R> + Send + Sync + 'static + Clone, E2: Send + Sync + 'static, X: Send + Sync + 'static,

Runs a cleanup effect if this effect is interrupted.

Source

pub fn acquire_release<F, R2, E2, X>(self, release: F) -> Effect<R, E, A>
where F: FnOnce(A, ScopeExit) -> Effect<R2, E2, X> + Send + Sync + 'static + Clone, R: Clone + Send + Sync + 'static, R2: From<R> + Send + Sync + 'static + Clone, E: Send + Sync + 'static, A: Send + Sync + Clone + 'static, X: Send + Sync + 'static, E2: Send + Sync + 'static,

Acquires a resource, then registers a finalizer to release it. The release effect is guaranteed to run when the scope closes.

Source

pub fn fork(self) -> Effect<R, E, Fiber<E, A>>
where R: Clone + Send + Sync + 'static, E: Send + Sync + Clone + 'static, A: Send + Sync + Clone + 'static,

Forks the effect into a new fiber.

Source

pub fn zip_par<B>(self, other: Effect<R, E, B>) -> Effect<R, E, (A, B)>
where R: Clone + Send + Sync + 'static, E: Send + Sync + Clone + 'static, A: Send + Sync + Clone + 'static, B: Send + Sync + Clone + 'static,

Runs this effect and another effect in parallel, returning both results. If either effect fails, the other is interrupted.

Source

pub fn race(self, other: Effect<R, E, A>) -> Effect<R, E, A>
where R: Clone + Send + Sync + 'static, E: Send + Sync + Clone + 'static, A: Send + Sync + Clone + 'static,

Source

pub fn collect_all_par<I>(effects: I) -> Effect<R, E, Vec<A>>
where I: IntoIterator<Item = Effect<R, E, A>>, I::IntoIter: Send, R: Clone + Send + Sync + 'static, E: Send + Sync + Clone + 'static, A: Send + Sync + Clone + 'static,

Source§

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

Source

pub fn retry<Out>(self, policy: Schedule<E, Out>) -> Effect<R, E, A>
where Out: Send + Sync + 'static + Clone,

Trait Implementations§

Source§

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<R, E, A> Freeze for Effect<R, E, A>

§

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

§

impl<R, E, A> Send for Effect<R, E, A>

§

impl<R, E, A> Sync for Effect<R, E, A>

§

impl<R, E, A> Unpin for Effect<R, E, A>

§

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

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> 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 = 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more