Skip to main content

EarlyReturn

Enum EarlyReturn 

Source
pub enum EarlyReturn<Return, Expr = ()> {
    Expr(Expr),
    Return(Return),
}
Expand description

§EarlyReturn

an enum that shows a value returned from a function should be returned early or not.

Variants§

§

Expr(Expr)

Treat the value as an expression.

§

Return(Return)

Treat the value as a return value.

Implementations§

Source§

impl<R, E> EarlyReturn<R, E>

Source

pub fn expr(e: E) -> Self

Source

pub fn ret(r: R) -> Self

Source

pub fn swap(self) -> EarlyReturn<E, R>

Swap the return and expression value.

Source

pub fn or_return<Expr2>( self, res: EarlyReturn<R, Expr2>, ) -> EarlyReturn<R, Expr2>

get the second value if the first value is EarlyReturn::Expr, otherwise return the first value.

Source

pub fn or_expr<Return2>( self, res: EarlyReturn<Return2, E>, ) -> EarlyReturn<Return2, E>

get the second value if the first value is EarlyReturn::Return, otherwise return the first value.

Source

pub fn map<F: FnOnce(E) -> E2, E2>(self, f: F) -> EarlyReturn<R, E2>

Map the expression value.

Source

pub async fn process_map<P: Processor<E>>( self, processor: &P, ) -> EarlyReturn<R, Result<P::Output, P::Error>>
where E: Send,

Map the expression value with an async function.

Source

pub fn map_return<F: FnOnce(R) -> R2, R2>(self, f: F) -> EarlyReturn<R2, E>

Map the return value.

Source

pub fn flat_map<F: FnOnce(E) -> EarlyReturn<R, E2>, E2>( self, f: F, ) -> EarlyReturn<R, E2>

Bind function of the monad.

Source

pub async fn process_flat_map<P: Processor<E, Output = EarlyReturn<R, E2>>, E2>( self, processor: &P, ) -> EarlyReturn<R, Result<E2, P::Error>>
where E: Send,

Bind function of the monad with an async function.

Source

pub fn from_result<Ok>(res: Result<E, R>) -> EarlyReturn<Result<Ok, R>, E>

Create an early return from a result. The error is treated as the return value.

Source§

impl<R, E> EarlyReturn<R, EarlyReturn<R, E>>

Source

pub fn flatten(self) -> EarlyReturn<R, E>

Flatten the early return.

Source§

impl<R, E> EarlyReturn<R, &E>

Source

pub fn copied_expr(self) -> EarlyReturn<R, E>
where E: Copy,

Copy the expression value.

Source

pub fn cloned_expr(self) -> EarlyReturn<R, E>
where E: Clone,

Clone the expression value.

Source

pub fn owned_expr<Owned>(self) -> EarlyReturn<R, Owned>
where E: ToOwned<Owned = Owned>,

Convert the expression value to an owned value.

Source§

impl<Succ, Err, Expr> EarlyReturn<Result<Succ, Err>, Expr>

Source

pub fn try_map<F: FnOnce(Expr) -> Result<Expr2, Err2>, Expr2, Err2: Into<Err>>( self, f: F, ) -> EarlyReturn<Result<Succ, Err>, Expr2>

Map the expression value with a fallible function. Return the error if the function returns an error.

Source

pub async fn try_process_map<P: Processor<Expr, Output = Expr2, Error = Err>, Expr2>( self, processor: &P, ) -> EarlyReturn<Result<Succ, Err>, Expr2>
where Expr: Send,

Map the expression value with an async fallible function. Return the error if the function returns an error.

Source§

impl<T> EarlyReturn<T, T>

Source

pub fn safe_unwrap(self) -> T

Unwrap the early return.

Auto Trait Implementations§

§

impl<Return, Expr> Freeze for EarlyReturn<Return, Expr>
where Expr: Freeze, Return: Freeze,

§

impl<Return, Expr> RefUnwindSafe for EarlyReturn<Return, Expr>
where Expr: RefUnwindSafe, Return: RefUnwindSafe,

§

impl<Return, Expr> Send for EarlyReturn<Return, Expr>
where Expr: Send, Return: Send,

§

impl<Return, Expr> Sync for EarlyReturn<Return, Expr>
where Expr: Sync, Return: Sync,

§

impl<Return, Expr> Unpin for EarlyReturn<Return, Expr>
where Expr: Unpin, Return: Unpin,

§

impl<Return, Expr> UnsafeUnpin for EarlyReturn<Return, Expr>
where Expr: UnsafeUnpin, Return: UnsafeUnpin,

§

impl<Return, Expr> UnwindSafe for EarlyReturn<Return, Expr>
where Expr: UnwindSafe, Return: 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> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
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.