[−][src]Enum tear::ValRet
Represents a usable value or an early return. Use with tear!
Description
The idea is to type an early return. The early return either evaluates to something (Val) or returns early (Ret).
Variants
The usable value
The return value
Implementations
impl<V, R> ValRet<V, R>
[src]
NB: Other combinators such as and
, and_then
, or
, map_val
aren't implemented because I didn't need them and not because they aren't useful.
Examples will all use the following two variables
let ok: ValRet<&str, &str> = Val("ok"); let error: ValRet<&str, &str> = Ret("error");
pub fn valret(self) -> Self
[src]
Optimization (?) for the Return trait
pub fn map_ret<R1>(self, f: impl FnOnce(R) -> R1) -> ValRet<V, R1>
[src]
Returns a new ValRet where we map the old Ret to the new Ret using the function supplied
assert_eq![ ok.map_ret(|_| -1), Val("ok") ]; assert_eq![ error.map_ret(|_| -1), Ret(-1) ];
pub fn or_else<R1>(self, f: impl FnOnce(R) -> ValRet<V, R1>) -> ValRet<V, R1>
[src]
Returns itself if it's a Val, otherwise calls the function to create a new ValRet based on the value of Ret.
fn recover (e: &str) -> ValRet<&str, i32> { if e == "error" { Val("recover") } else { Ret(-1) } } assert_eq![ ok.or_else(recover), Val("ok") ]; assert_eq![ error.or_else(recover), Val("recover") ];
Trait Implementations
impl<V: Debug, R: Debug> Debug for ValRet<V, R>
[src]
impl<T, R> Judge for ValRet<T, R>
[src]
type Positive = T
This is considered Good
type Negative = R
This is considered Bad
fn into_moral(self) -> Moral<T, R>
[src]
fn from_good(v: T) -> Self
[src]
fn from_bad(r: R) -> Self
[src]
impl<V: PartialEq, R: PartialEq> PartialEq<ValRet<V, R>> for ValRet<V, R>
[src]
impl<V, R> StructuralPartialEq for ValRet<V, R>
[src]
Auto Trait Implementations
impl<V, R> RefUnwindSafe for ValRet<V, R> where
R: RefUnwindSafe,
V: RefUnwindSafe,
R: RefUnwindSafe,
V: RefUnwindSafe,
impl<V, R> Send for ValRet<V, R> where
R: Send,
V: Send,
R: Send,
V: Send,
impl<V, R> Sync for ValRet<V, R> where
R: Sync,
V: Sync,
R: Sync,
V: Sync,
impl<V, R> Unpin for ValRet<V, R> where
R: Unpin,
V: Unpin,
R: Unpin,
V: Unpin,
impl<V, R> UnwindSafe for ValRet<V, R> where
R: UnwindSafe,
V: UnwindSafe,
R: UnwindSafe,
V: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, E, Me> Return<T, E> for Me where
Me: Judge<Positive = T, Negative = E>,
[src]
Me: Judge<Positive = T, Negative = E>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,