Enum w_result::WResult [] [src]

#[must_use]
pub enum WResult<T, W, E> {
    WOk(T, Vec<W>),
    WErr(E),
}

A result type that carries warnings.

Variants

WOk

Contains the success value along with any accumulated warnings.

WErr

Contains the error value.

Methods

impl<T, W, E> WResult<T, W, E>

fn is_ok(&self) -> bool

Returns true if this WResult is WOk

fn is_err(&self) -> bool

Returns true if this WResult is WErr

fn is_warn_or_err(&self) -> bool

Returns true if this WResult is WErr or if it is WOk but contains warnings.

fn ok_discard(self) -> Option<T>

Converts this WResult to an Option by taking the taking the WOk value or mapping WErr to None. Any warnings are discarded.

fn err(self) -> Option<E>

Converts this WResult to an Option by taking the WErr variant or mapping WOk to None.

fn ok_werr(self) -> Option<T>

Converts this WResult to an Option by taking the WOk variant or mapping WErr to None. This function is similar to ok_discard except if there are any warnings then they are treated as errors and this function returns None.

fn map<U, F>(self, op: F) -> WResult<U, W, E> where F: FnOnce(T) -> U

Map the WOk value of this WResult, if any.

fn map_err<U, F>(self, op: F) -> WResult<T, W, U> where F: FnOnce(E) -> U

Map the WErr value of this WResult, if any.

fn map_warnings<U, F>(self, op: F) -> WResult<T, U, E> where F: FnMut(W) -> U

Map the warnings of this WResult.

fn and<U>(self, res: WResult<U, W, E>) -> WResult<U, W, E>

If self is WOk, returns res with the warnings from self accumulated into the final result. Otherwise returns the WErr value of self.

fn and_then<U, V, F>(self, op: F) -> WResult<U, V, E> where F: FnOnce(T, Vec<W>) -> WResult<U, V, E>

If self is WOk, returns the result of applying op to self's value and warnings. Otherwise returns the WErr value of self.

fn or<U>(self, res: WResult<T, W, U>) -> WResult<T, W, U>

If self is WOk returns self. Otherwise returns res.

fn or_else<U, F>(self, op: F) -> WResult<T, W, F> where F: FnOnce(E) -> WResult<T, W, F>

If self is WOk returns self. Otherwise returns the result of applying op to self's error value.

fn result_discard(self) -> Result<T, E>

Convert this WResult<T, W, E> to a Result<T, E>, discarding any errors. See also result_log for a version of this function that logs warnings.

fn result_werr_res(self) -> Result<T, Result<W, E>>

Convert this WResult<T, W, E> to a Result<T, Result<W, E>>. This is a way to convert from WResult to Result, treating warnings as errors but allowing W and E to be two different types. See also result_werr for when W and E are the same type. If there are multiple warnings the first is returned.

fn unwrap_discard_or(self, optb: T) -> T

If self is WOk, unwraps it discarding any warnings. Otherwise returns optb. See also unwrap_log_or for a version of this function that logs warnings.

fn unwrap_or_werr(self, optb: T) -> T

If self is WOk and has no warnings, unwraps it. Otherwise returns optb.

fn unwrap_discard_or_else<F>(self, op: F) -> T where F: FnOnce(E) -> T

If self is WOk, unwraps it discarding any warnings. Otherwise returns the result of applying op to self's error value. See also unwrap_log_or_else for a version of this function that logs warnings.

impl<T, E> WResult<T, E, E>

fn err_werr(self) -> Option<E>

Take the error value of this WResult, if any. Otherwise returns the first warning, if any. This function is the same as WResult::err except that warnings are treated as errors.

fn result_werr(self) -> Result<T, E>

Convert this WResult to a Result but treat warnings as errors. If there are multiple warnings the first is returned.

fn unwrap_or_else_werr<F>(self, op: F) -> T where F: FnOnce(E) -> T

If self is WOk and has no warnings then unwrap it. Otherwise return the result of applying op to self's error or first warning.

impl<T, W, E> WResult<T, W, E> where W: Display

fn ok_log(self) -> Option<T>

Take the WOk value of self, if any. Warnings are logged using the warn! macro before being discarded.

fn result_log(self) -> Result<T, E>

Convert this WResult<T, W, E> to a Result<T, E>. Warnings are logged using the warn! macro before being discarded.

fn unwrap_log_or(self, optb: T) -> T

If self is WOk, unwrap it and log any warnings using the warn! macro. Otherwise return optb.

fn unwrap_log_or_else<F>(self, op: F) -> T where F: FnOnce(E) -> T

If self is WOk, unwrap it and log any warnings using the warn! macro. Otherwise return the result of applying op to self's error value.

Trait Implementations

impl<T, W, E> From<Result<T, E>> for WResult<T, W, E>

fn from(val: Result<T, E>) -> WResult<T, W, E>

impl<A, T, W, E> FromIterator<WResult<A, W, E>> for WResult<T, W, E> where T: FromIterator<A>

fn from_iter<I>(iter: I) -> Self where I: IntoIterator<Item=WResult<A, W, E>>