Skip to main content

ShortCircuit

Struct ShortCircuit 

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

Short-circuits on the first Err in a yielded Result.

Converts Sans<I, Result<O, E>, Return = P> to Sans<I, O, Return = Result<P, E>>. If any yield is Err(e), immediately completes with Err(e). Otherwise yields unwrapped Ok values and completes with Ok(P).

Trait Implementations§

Source§

impl<I, O, E, S> InitSans<I, O> for ShortCircuit<S, E>
where S: InitSans<I, Result<O, E>>,

Source§

type Next = ShortCircuit<<S as InitSans<I, Result<O, E>>>::Next, E>

Source§

fn init( self, ) -> Step<(O, Self::Next), Result<<S::Next as Sans<I, Result<O, E>>>::Return, E>>

Execute the first coroutine. Read more
Source§

fn chain<R>(self, r: R) -> Chain<Self, R>
where Self: Sized, Self::Next: Sans<I, O, Return = I>, R: Sans<I, O>,

Chain with a coroutine.
Source§

fn chain_once<F>(self, f: F) -> Chain<Self, Once<F>>
where Self: Sized, Self::Next: Sans<I, O, Return = I>, F: FnOnce(<Self::Next as Sans<I, O>>::Return) -> O,

Chain with a function that executes once.
Source§

fn chain_repeat<F>(self, f: F) -> Chain<Self, Repeat<F>>
where Self: Sized, Self::Next: Sans<I, O, Return = I>, F: FnMut(<Self::Next as Sans<I, O>>::Return) -> O,

Chain with a function that repeats indefinitely.
Source§

fn map_input<I2, F>(self, f: F) -> MapInput<Self, F>
where Self: Sized, F: FnMut(I2) -> I,

Transform inputs before they reach the underlying coroutine.
Source§

fn map_yield<O2, F>(self, f: F) -> MapYield<Self, F, I, O>
where Self: Sized, F: FnMut(O) -> O2,

Transform yielded values before returning them.
Source§

fn map_done<D2, F>(self, f: F) -> MapReturn<Self, F>
where Self: Sized, F: FnMut(<Self::Next as Sans<I, O>>::Return) -> D2,

Transform the final result when completing.
Source§

fn into_iter(self) -> InitSansIter<O, Self> ⓘ
where Self: Sized + InitSans<(), O>,

Convert to an iterator.
Source§

impl<I, O, E, S> Sans<I, O> for ShortCircuit<S, E>
where S: Sans<I, Result<O, E>>,

Source§

type Return = Result<<S as Sans<I, Result<O, E>>>::Return, E>

Type of final result when computation completes
Source§

fn next(&mut self, input: I) -> Step<O, Self::Return>

Process input, returning Yield to continue or Return to complete.
Source§

fn and_then<T, F>(self, f: F) -> AndThen<Self, T::Next, F>
where Self: Sized + Sans<I, O, Return = I>, T: InitSans<I, O>, F: FnOnce(Self::Return) -> T,

Chain with a coroutine created from this coroutine’s return value. Read more
Source§

fn boxed(self) -> Box<dyn Sans<I, O, Return = Self::Return>>
where Self: Sized + 'static,

Source§

fn chain<R>(self, r: R) -> Chain<Self, R>
where Self: Sized + Sans<I, O, Return = I>, R: Sans<I, O>,

Chain with another coroutine.
Source§

fn chain_once<F>(self, f: F) -> Chain<Self, Once<F>>
where Self: Sized + Sans<I, O, Return = I>, F: FnOnce(Self::Return) -> O,

Chain with a function that executes once.
Source§

fn chain_repeat<F>(self, f: F) -> Chain<Self, Repeat<F>>
where Self: Sized + Sans<I, O, Return = I>, F: FnMut(Self::Return) -> O,

Chain with a function that repeats indefinitely.
Source§

fn map_input<I2, F>(self, f: F) -> MapInput<Self, F>
where Self: Sized, F: FnMut(I2) -> I,

Transform inputs before they reach this coroutine.
Source§

fn map_yield<O2, F>(self, f: F) -> MapYield<Self, F, I, O>
where Self: Sized, F: FnMut(O) -> O2,

Transform yielded values before returning them.
Source§

fn map_return<D2, F>(self, f: F) -> MapReturn<Self, F>
where Self: Sized, F: FnMut(Self::Return) -> D2,

Transform the final result when completing.
Source§

fn into_iter(self) -> SansIter<O, Self> ⓘ
where Self: Sized + Sans<(), O>,

Convert to an iterator.

Auto Trait Implementations§

§

impl<S, E> Freeze for ShortCircuit<S, E>
where S: Freeze, PhantomData<E>: Freeze,

§

impl<S, E> RefUnwindSafe for ShortCircuit<S, E>

§

impl<S, E> Send for ShortCircuit<S, E>
where S: Send, PhantomData<E>: Send,

§

impl<S, E> Sync for ShortCircuit<S, E>
where S: Sync, PhantomData<E>: Sync,

§

impl<S, E> Unpin for ShortCircuit<S, E>
where S: Unpin, PhantomData<E>: Unpin,

§

impl<S, E> UnsafeUnpin for ShortCircuit<S, E>

§

impl<S, E> UnwindSafe for ShortCircuit<S, E>

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. 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<I, O, S> TryInitSans<I, O> for S
where S: InitSans<I, O>,

Source§

fn ok_map<P, E, T, F>(self, f: F) -> OkMap<Self, T::Next, F>
where Self: InitSans<I, O>, Self::Next: Sans<I, O, Return = Result<P, E>>, T: InitSans<I, O>, T::Next: Sans<I, O>, F: FnOnce(P) -> T,

Maps Ok return values through a function that produces an InitSans.
Source§

fn ok_and_then<P, Q, E, T, F>(self, f: F) -> OkAndThen<Self, T::Next, F>
where Self: InitSans<I, O>, Self::Next: Sans<I, O, Return = Result<P, E>>, T: InitSans<I, O>, T::Next: Sans<I, O, Return = Result<Q, E>>, F: FnOnce(P) -> T,

Chains through a function that produces an InitSans with a Result return type.
Source§

fn ok_chain<E, R>(self, next: R) -> OkChain<Self, R>
where Self: InitSans<I, O>, Self::Next: Sans<I, O, Return = Result<I, E>>, R: Sans<I, O>,

Chains to another coroutine only if the first returns Ok.
Source§

fn flatten<T, E>(self) -> Flatten<Self>
where Self: InitSans<I, O>, Self::Next: Sans<I, O, Return = Result<Result<T, E>, E>>,

Flattens nested Result types in the return value.
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<I, O, S> TrySans<I, O> for S
where S: Sans<I, O>,

Source§

fn ok_map<P, E, T, F>(self, f: F) -> OkMap<Self, T::Next, F>
where Self: Sans<I, O, Return = Result<P, E>>, T: InitSans<I, O>, T::Next: Sans<I, O>, F: FnOnce(P) -> T,

Maps Ok return values through a function that produces an InitSans.
Source§

fn ok_and_then<P, Q, E, T, F>(self, f: F) -> OkAndThen<Self, T::Next, F>
where Self: Sans<I, O, Return = Result<P, E>>, T: InitSans<I, O>, T::Next: Sans<I, O, Return = Result<Q, E>>, F: FnOnce(P) -> T,

Chains through a function that produces an InitSans with a Result return type.
Source§

fn ok_chain<E, R>(self, next: R) -> OkChain<Self, R>
where Self: Sans<I, O, Return = Result<I, E>>, R: Sans<I, O>,

Chains to another coroutine only if the first returns Ok.
Source§

fn flatten<T, E>(self) -> Flatten<Self>
where Self: Sans<I, O, Return = Result<Result<T, E>, E>>,

Flattens nested Result types in the return value.