[][src]Enum tear::ValRet

pub enum ValRet<V, R> {
    Val(V),
    Ret(R),
}

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

Val(V)

The usable value

Ret(R)

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

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

impl<V, R> Send for ValRet<V, R> where
    R: Send,
    V: Send

impl<V, R> Sync for ValRet<V, R> where
    R: Sync,
    V: Sync

impl<V, R> Unpin for ValRet<V, R> where
    R: Unpin,
    V: Unpin

impl<V, R> UnwindSafe for ValRet<V, R> where
    R: UnwindSafe,
    V: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, E, Me> Return<T, E> for Me where
    Me: Judge<Positive = T, Negative = E>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.