pub enum Result<T, L, F> {
    Success(T),
    LocalErr(L),
    FatalErr(F),
}
Expand description

A type representing success (Success), a local error (LocalErr), or a fatal error (FatalErr).

See the woah top-level documentation for details.

Variants

Success(T)

Contains the success value.

LocalErr(L)

Contains a local error value (which should be handled)

FatalErr(F)

Contains a fatal error value (which should be propagated)

Implementations

Convert woah::Result<T, L, F> into a Result<Result<T, L>, F>, which is equivalent in ? behavior.

Example
use woah::prelude::*;

let result: StdResult<StdResult<i64, &str>, &str> = LocalErr("a local error").into_result();
assert_eq!(result, Ok(Err("a local error")));

Construct either a Success or LocalErr variant based on a Result.

Example
use woah::prelude::*;

let result: Result<i64, &str, &str> = Result::from_result(Ok(0));
assert_eq!(result, Success(0));

Construct the Success variant based on some success value.

Example
use woah::prelude::*;

let fatal_err: Result<i64, &str, &str> = Result::from_success(0);
assert_eq!(fatal_err, Success(0));

Construct the LocalErr variant based on some error.

Example
use woah::prelude::*;

let fatal_err: Result<i64, &str, &str> = Result::from_fatal_error("a fatal error");
assert_eq!(fatal_err, FatalErr("a fatal error"));

Construct the FatalErr variant based on some error.

Example
use woah::prelude::*;

let fatal_err: Result<i64, &str, &str> = Result::from_fatal_error("a fatal error");
assert_eq!(fatal_err, FatalErr("a fatal error"));

Returns true if the result is Success.

Example
use woah::prelude::*;

let x: Result<i32, &str, &str> = Success(-3);
assert_eq!(x.is_success(), true);

let x: Result<i32, &str, &str> = LocalErr("Some error message");
assert_eq!(x.is_success(), false);

let x: Result<i32, &str, &str> = FatalErr("Another error message");
assert_eq!(x.is_success(), false);

Returns true if the result is LocalErr or FatalErr.

Example
use woah::prelude::*;

let x: Result<i32, &str, &str> = Success(-3);
assert_eq!(x.is_err(), false);

let x: Result<i32, &str, &str> = LocalErr("Some error message");
assert_eq!(x.is_err(), true);

let x: Result<i32, &str, &str> = FatalErr("Another error message");
assert_eq!(x.is_err(), true);

Returns true if the result is LocalErr.

Example
use woah::prelude::*;

let x: Result<i32, &str, &str> = Success(-3);
assert_eq!(x.is_local_err(), false);

let x: Result<i32, &str, &str> = LocalErr("Some error message");
assert_eq!(x.is_local_err(), true);

let x: Result<i32, &str, &str> = FatalErr("Another error message");
assert_eq!(x.is_local_err(), false);

Returns true if the result is FatalErr.

Example
use woah::prelude::*;

let x: Result<i32, &str, &str> = Success(-3);
assert_eq!(x.is_fatal_err(), false);

let x: Result<i32, &str, &str> = LocalErr("Some error message");
assert_eq!(x.is_fatal_err(), false);

let x: Result<i32, &str, &str> = FatalErr("Another error message");
assert_eq!(x.is_fatal_err(), true);

Returns true if the result is a Success value containing the given value.

Examples
use woah::prelude::*;

let x: Result<u32, &str, &str> = Success(2);
assert_eq!(x.contains(&2), true);

let x: Result<u32, &str, &str> = Success(3);
assert_eq!(x.contains(&2), false);

let x: Result<u32, &str, &str> = LocalErr("Some error message");
assert_eq!(x.contains(&2), false);

Returns true if the result is a LocalErr or FatalErr value containing the given value.

Examples
use woah::prelude::*;
use either::Either;

let x: Result<&str, u32, &str> = LocalErr(2);
let check: Either<_, &&str> = Either::Left(&2);
assert_eq!(x.contains_err(check), true);

let x: Result<&str, &str, u32> = FatalErr(3);
let check: Either<&&str, _> = Either::Right(&2);
assert_eq!(x.contains_err(check), false);

let x: Result<u32, &str, &str> = Success(0);
let check: Either<&&str, &&str> = Either::Left(&"");
assert_eq!(x.contains_err(check), false);

Returns true if the result is a LocalErr value containing the given value.

Examples
use woah::prelude::*;

let x: Result<&str, u32, &str> = LocalErr(2);
assert_eq!(x.contains_local_err(&2), true);

let x: Result<&str, u32, &str> = LocalErr(3);
assert_eq!(x.contains_local_err(&2), false);

let x: Result<&str, u32, &str> = Success("Some error message");
assert_eq!(x.contains_local_err(&2), false);

Returns true if the result is a FatalErr value containing the given value.

Examples
use woah::prelude::*;

let x: Result<&str, &str, u32> = FatalErr(2);
assert_eq!(x.contains_fatal_err(&2), true);

let x: Result<&str, &str, u32> = FatalErr(3);
assert_eq!(x.contains_fatal_err(&2), false);

let x: Result<&str, &str, u32> = Success("Some error message");
assert_eq!(x.contains_fatal_err(&2), false);

Convert a Success variant to an Option::Some, otherwise to a None.

Example
use woah::prelude::*;

let x: Result<u32, &str, &str> = Success(2);
assert_eq!(x.success(), Some(2));

let x: Result<&str, u32, &str> = LocalErr(2);
assert_eq!(x.success(), None);

let x: Result<&str, &str, u32> = FatalErr(2);
assert_eq!(x.success(), None);

Convert a LocalErr or FatalErr variant to an Option<Either<_, _>>, otherwise to a None.

Example
use woah::prelude::*;
use either::Either::{self, Left, Right};

let x: Result<u32, &str, &str> = Success(2);
assert_eq!(x.err(), None);

let x: Result<&str, u32, &str> = LocalErr(2);
assert_eq!(x.err(), Some(Left(2)));

let x: Result<&str, &str, u32> = FatalErr(2);
assert_eq!(x.err(), Some(Right(2)));

Convert a LocalErr variant to an Option::Some, otherwise to a None.

Example
use woah::prelude::*;

let x: Result<u32, &str, &str> = Success(2);
assert_eq!(x.local_err(), None);

let x: Result<&str, u32, &str> = LocalErr(2);
assert_eq!(x.local_err(), Some(2));

let x: Result<&str, &str, u32> = FatalErr(2);
assert_eq!(x.local_err(), None);

Convert a FatalErr variant to an Option::Some, otherwise to a None.

Example
use woah::prelude::*;

let x: Result<u32, &str, &str> = Success(2);
assert_eq!(x.fatal_err(), None);

let x: Result<&str, u32, &str> = LocalErr(2);
assert_eq!(x.fatal_err(), None);

let x: Result<&str, &str, u32> = FatalErr(2);
assert_eq!(x.fatal_err(), Some(2));

Get a reference to the contained value.

Example
use woah::prelude::*;

let x: Result<u32, u32, u32> = Success(0);
assert_eq!(x.as_ref(), Success(&0));

let x: Result<u32, u32, u32> = LocalErr(0);
assert_eq!(x.as_ref(), LocalErr(&0));

let x: Result<u32, u32, u32> = FatalErr(0);
assert_eq!(x.as_ref(), FatalErr(&0));

Get a mutable reference to the contained value.

Example
use woah::prelude::*;

let mut x: Result<u32, u32, u32> = Success(0);
assert_eq!(x.as_mut(), Success(&mut 0));

let mut x: Result<u32, u32, u32> = LocalErr(0);
assert_eq!(x.as_mut(), LocalErr(&mut 0));

let mut x: Result<u32, u32, u32> = FatalErr(0);
assert_eq!(x.as_mut(), FatalErr(&mut 0));

Apply a function to the contained value if it’s a Success.

Example
use woah::prelude::*;

let x: Result<u32, u32, u32> = Success(0);
assert_eq!(x.map(|s| s + 1), Success(1));

let x: Result<u32, u32, u32> = LocalErr(0);
assert_eq!(x.map(|s| s + 1), LocalErr(0));

let x: Result<u32, u32, u32> = FatalErr(0);
assert_eq!(x.map(|s| s + 1), FatalErr(0));

Apply a function to the contained value if it’s a Success.

Otherwise return the provided value.

Example
use woah::prelude::*;

let x: Result<u32, u32, u32> = Success(0);
assert_eq!(x.map_or(5, |s| s + 1), 1);

let x: Result<u32, u32, u32> = LocalErr(0);
assert_eq!(x.map_or(5, |s| s + 1), 5);

let x: Result<u32, u32, u32> = FatalErr(0);
assert_eq!(x.map_or(5, |s| s + 1), 5);

Apply a function to the contained value if it’s a Success.

Otherwise run one of the provided default functions.

Example
use woah::prelude::*;

let x: Result<u32, u32, u32> = Success(0);
assert_eq!(x.map_or_else(|l| l + 3, |f| f + 2, |s| s + 1), 1);

let x: Result<u32, u32, u32> = LocalErr(0);
assert_eq!(x.map_or_else(|l| l + 3, |f| f + 2, |s| s + 1), 3);

let x: Result<u32, u32, u32> = FatalErr(0);
assert_eq!(x.map_or_else(|l| l + 3, |f| f + 2, |s| s + 1), 2);

Apply a function to the contained value if it’s a LocalErr or FatalErr.

Example
use woah::prelude::*;
use either::Either::{self, Left, Right};

fn modify_error(err: Either<u32, u32>) -> Either<u32, u32> {
    match err {
        Left(l) => Left(l + 1),
        Right(f) => Right(f + 1),
    }
}

let x: Result<u32, u32, u32> = Success(0);
assert_eq!(x.map_err(modify_error), Success(0));

let x: Result<u32, u32, u32> = LocalErr(0);
assert_eq!(x.map_err(modify_error), LocalErr(1));

let x: Result<u32, u32, u32> = FatalErr(0);
assert_eq!(x.map_err(modify_error), FatalErr(1));

Apply a function to the contained value if it’s a LocalErr.

Example
use woah::prelude::*;

let x: Result<u32, u32, u32> = Success(0);
assert_eq!(x.map_local_err(|l| l + 1), Success(0));

let x: Result<u32, u32, u32> = LocalErr(0);
assert_eq!(x.map_local_err(|l| l + 1), LocalErr(1));

let x: Result<u32, u32, u32> = FatalErr(0);
assert_eq!(x.map_local_err(|l| l + 1), FatalErr(0));

Apply a function to the contained value if it’s a FatalErr.

Example
use woah::prelude::*;

let x: Result<u32, u32, u32> = Success(0);
assert_eq!(x.map_fatal_err(|f| f + 1), Success(0));

let x: Result<u32, u32, u32> = LocalErr(0);
assert_eq!(x.map_fatal_err(|f| f + 1), LocalErr(0));

let x: Result<u32, u32, u32> = FatalErr(0);
assert_eq!(x.map_fatal_err(|f| f + 1), FatalErr(1));

Get an iterator over the inner value in the Result, if it’s a Success.

Example
use woah::prelude::*;

let r: Result<u32, &str, &str> = Success(0);

assert_eq!(r.iter().next(), Some(&0));

Get a mutable iterator over the inner value in the Result, if it’s a Success.

Example
use woah::prelude::*;

let mut r: Result<u32, &str, &str> = Success(0);

{
    let next = r.iter_mut().next();

    assert!(next.is_some());

    *next.unwrap() = 5;
}

assert_eq!(r, Success(5));

If it’s a Success, replace it with res.

Example
use woah::prelude::*;

let r1: Result<u32, &str, &str> = Success(0);
let r2: Result<u32, _, &str> = r1.and(LocalErr(""));
assert_eq!(r2, LocalErr(""));

If it’s a Success, replace it with the result of op.

Example
use woah::prelude::*;

let r1: Result<u32, &str, &str> = Success(0);
let r2: Result<u32, _, &str> = r1.and_then(|c| {
    if c == 0 {
        LocalErr("local")
    } else {
        FatalErr("fatal")
    }
});

assert_eq!(r2, LocalErr("local"));

If it’s a LocalErr or FatalErr, replace them with the appropriate value.

Example
use woah::prelude::*;

let l: Result<u32, u32, u32> = LocalErr(1);
let f: Result<u32, u32, u32> = FatalErr(2);

let r: Result<u32, u32, u32> = Success(0);
assert_eq!(r.or(l, f), Success(0));

let r: Result<u32, u32, u32> = LocalErr(0);
assert_eq!(r.or(l, f), LocalErr(1));

let r: Result<u32, u32, u32> = FatalErr(0);
assert_eq!(r.or(l, f), FatalErr(2));

If it’s a LocalErr, replace them with the given value.

Example
use woah::prelude::*;

let l: Result<u32, u32, u32> = LocalErr(1);

let r: Result<u32, u32, u32> = Success(0);
assert_eq!(r.or_local(l), Success(0));

let r: Result<u32, u32, u32> = LocalErr(0);
assert_eq!(r.or_local(l), LocalErr(1));

let r: Result<u32, u32, u32> = FatalErr(0);
assert_eq!(r.or_local(l), FatalErr(0));

If it’s a FatalErr, replace them with the given value.

Example
use woah::prelude::*;

let f: Result<u32, u32, u32> = FatalErr(2);

let r: Result<u32, u32, u32> = Success(0);
assert_eq!(r.or_fatal(f), Success(0));

let r: Result<u32, u32, u32> = LocalErr(0);
assert_eq!(r.or_fatal(f), LocalErr(0));

let r: Result<u32, u32, u32> = FatalErr(0);
assert_eq!(r.or_fatal(f), FatalErr(2));

If it’s a LocalErr or FatalErr, replace them with the appropriate function result.

Example
use woah::prelude::*;

let l = |l| LocalErr(l + 1);
let f = |f| FatalErr(f + 2);

let r: Result<u32, u32, u32> = Success(0);
assert_eq!(r.or_else(l, f), Success(0));

let r: Result<u32, u32, u32> = LocalErr(0);
assert_eq!(r.or_else(l, f), LocalErr(1));

let r: Result<u32, u32, u32> = FatalErr(0);
assert_eq!(r.or_else(l, f), FatalErr(2));

If it’s a LocalErr, replace it with the appropriate function result.

Example
use woah::prelude::*;

let l = |l| LocalErr(l + 1);

let r: Result<u32, u32, u32> = Success(0);
assert_eq!(r.or_else_local(l), Success(0));

let r: Result<u32, u32, u32> = LocalErr(0);
assert_eq!(r.or_else_local(l), LocalErr(1));

let r: Result<u32, u32, u32> = FatalErr(0);
assert_eq!(r.or_else_local(l), FatalErr(0));

If it’s a FatalErr, replace it with the appropriate function result.

Example
use woah::prelude::*;

let f = |f| FatalErr(f + 2);

let r: Result<u32, u32, u32> = Success(0);
assert_eq!(r.or_else_fatal(f), Success(0));

let r: Result<u32, u32, u32> = LocalErr(0);
assert_eq!(r.or_else_fatal(f), LocalErr(0));

let r: Result<u32, u32, u32> = FatalErr(0);
assert_eq!(r.or_else_fatal(f), FatalErr(2));

Return inner value if it’s a Success, or alt otherwise.

Example
use woah::prelude::*;

let r: Result<u32, u32, u32> = Success(0);
assert_eq!(r.unwrap_or(5), 0);

let r: Result<u32, u32, u32> = LocalErr(0);
assert_eq!(r.unwrap_or(5), 5);

let r: Result<u32, u32, u32> = FatalErr(0);
assert_eq!(r.unwrap_or(5), 5);

Return inner value if it’s a Success, or the appropriate function otherwise.

Example
use woah::prelude::*;

let l = |_| 5;
let f = |_| 10;

let r: Result<u32, u32, u32> = Success(0);
assert_eq!(r.unwrap_or_else(l, f), 0);

let r: Result<u32, u32, u32> = LocalErr(0);
assert_eq!(r.unwrap_or_else(l, f), 5);

let r: Result<u32, u32, u32> = FatalErr(0);
assert_eq!(r.unwrap_or_else(l, f), 10);

Copy the value if it’s a Success.

Example
use woah::prelude::*;

let r: Result<&u32, (), ()> = Success(&0);
assert_eq!(r.copied(), Success(0));

Copy the value if it’s a Success.

Example
use woah::prelude::*;

let r: Result<&u32, (), ()> = Success(&0);
assert_eq!(r.copied(), Success(0));

Clone the value if it’s a Success.

Example
use woah::prelude::*;

let r: Result<&u32, (), ()> = Success(&0);
assert_eq!(r.cloned(), Success(0));

Clone the value if it’s a Success.

Example
use woah::prelude::*;

let r: Result<&u32, (), ()> = Success(&0);
assert_eq!(r.cloned(), Success(0));

Get the value if it’s a Success, panic otherwise.

Example
use woah::prelude::*;

let r: Result<u32, (), ()> = Success(0);
assert_eq!(r.unwrap(), 0);

Get the value if it’s a Success, panic with a msg otherwise.

Example
use woah::prelude::*;

let r: Result<u32, (), ()> = Success(0);
assert_eq!(r.expect("should be success"), 0);

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Creates a value from an iterator. Read more

🔬 This is a nightly-only experimental API. (try_trait_v2 #84277)

Constructs the type from a compatible Residual type. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Method which takes an iterator and generates Self from the elements by multiplying the items. Read more

Serialize this value into the given Serde serializer. Read more

Method which takes an iterator and generates Self from the elements by “summing up” the items. Read more

Is called to get the representation of the value as status code. This status code is returned to the operating system. Read more

Is called to get the representation of the value as status code. This status code is returned to the operating system. Read more

🔬 This is a nightly-only experimental API. (try_trait_v2 #84277)

The type of the value produced by ? when not short-circuiting.

🔬 This is a nightly-only experimental API. (try_trait_v2 #84277)

The type of the value passed to FromResidual::from_residual as part of ? when short-circuiting. Read more

🔬 This is a nightly-only experimental API. (try_trait_v2 #84277)

Constructs the type from its Output type. Read more

🔬 This is a nightly-only experimental API. (try_trait_v2 #84277)

Used in ? to decide whether the operator should produce a value (because this returned ControlFlow::Continue) or propagate a value back to the caller (because this returned ControlFlow::Break). Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into #41263)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.