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§
Implementations§
Source§impl<R, E> EarlyReturn<R, E>
impl<R, E> EarlyReturn<R, E>
Sourcepub fn expr(e: E) -> Self
pub fn expr(e: E) -> Self
Create an EarlyReturn::Expr
Sourcepub fn ret(r: R) -> Self
pub fn ret(r: R) -> Self
Create an EarlyReturn::Return
Sourcepub fn swap(self) -> EarlyReturn<E, R>
pub fn swap(self) -> EarlyReturn<E, R>
Swap the return and expression value.
Sourcepub fn or_return<Expr2>(
self,
res: EarlyReturn<R, Expr2>,
) -> EarlyReturn<R, Expr2>
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.
Sourcepub fn or_expr<Return2>(
self,
res: EarlyReturn<Return2, E>,
) -> EarlyReturn<Return2, E>
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.
Sourcepub fn map<F: FnOnce(E) -> E2, E2>(self, f: F) -> EarlyReturn<R, E2>
pub fn map<F: FnOnce(E) -> E2, E2>(self, f: F) -> EarlyReturn<R, E2>
Map the expression value.
Sourcepub async fn process_map<P: Processor<E>>(
self,
processor: &P,
) -> EarlyReturn<R, Result<P::Output, P::Error>>where
E: Send,
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.
Sourcepub fn map_return<F: FnOnce(R) -> R2, R2>(self, f: F) -> EarlyReturn<R2, E>
pub fn map_return<F: FnOnce(R) -> R2, R2>(self, f: F) -> EarlyReturn<R2, E>
Map the return value.
Sourcepub fn flat_map<F: FnOnce(E) -> EarlyReturn<R, E2>, E2>(
self,
f: F,
) -> EarlyReturn<R, E2>
pub fn flat_map<F: FnOnce(E) -> EarlyReturn<R, E2>, E2>( self, f: F, ) -> EarlyReturn<R, E2>
Bind function of the monad.
Sourcepub 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,
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.
Sourcepub fn from_result<Ok>(res: Result<E, R>) -> EarlyReturn<Result<Ok, R>, E>
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>>
impl<R, E> EarlyReturn<R, EarlyReturn<R, E>>
Sourcepub fn flatten(self) -> EarlyReturn<R, E>
pub fn flatten(self) -> EarlyReturn<R, E>
Flatten the early return.
Source§impl<R, E> EarlyReturn<R, &E>
impl<R, E> EarlyReturn<R, &E>
Sourcepub fn copied_expr(self) -> EarlyReturn<R, E>where
E: Copy,
pub fn copied_expr(self) -> EarlyReturn<R, E>where
E: Copy,
Copy the expression value.
Sourcepub fn cloned_expr(self) -> EarlyReturn<R, E>where
E: Clone,
pub fn cloned_expr(self) -> EarlyReturn<R, E>where
E: Clone,
Clone the expression value.
Sourcepub fn owned_expr<Owned>(self) -> EarlyReturn<R, Owned>where
E: ToOwned<Owned = Owned>,
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>
impl<Succ, Err, Expr> EarlyReturn<Result<Succ, Err>, Expr>
Sourcepub fn try_map<F: FnOnce(Expr) -> Result<Expr2, Err2>, Expr2, Err2: Into<Err>>(
self,
f: F,
) -> EarlyReturn<Result<Succ, Err>, Expr2>
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.
Sourcepub async fn try_process_map<P: Processor<Expr, Output = Expr2, Error = Err>, Expr2>(
self,
processor: &P,
) -> EarlyReturn<Result<Succ, Err>, Expr2>where
Expr: Send,
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>
impl<T> EarlyReturn<T, T>
Sourcepub fn safe_unwrap(self) -> T
pub fn safe_unwrap(self) -> T
Unwrap the early return.
Auto Trait Implementations§
impl<Return, Expr> Freeze for EarlyReturn<Return, Expr>
impl<Return, Expr> RefUnwindSafe for EarlyReturn<Return, Expr>where
Expr: RefUnwindSafe,
Return: RefUnwindSafe,
impl<Return, Expr> Send for EarlyReturn<Return, Expr>
impl<Return, Expr> Sync for EarlyReturn<Return, Expr>
impl<Return, Expr> Unpin for EarlyReturn<Return, Expr>
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> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.