Module woah::docs [−][src]
Expand description
Documentation, including crate features and examples.
Why are the docs like this?
Putting the docs in Rustdoc means they can be run as documentation tests. Breaking them up into modules helps keep them from getting too unwieldy, so people can still navigate the API itself with ease.
woah::Result
has a lot of methods, and the way they’re grouped and presented by Rustdoc isn’t always
easy to navigate. To help, this page explains them in groups of similar methods.
Methods
See if the Result
is a particular variant
These methods, the “is” methods, return a bool
based on what variant is present.
See if the Result
contains a value
These methods check if the Result
contains a particular value.
Get an Option
if a variant is present
These methods try to get the contained value out, returning an Option
in case it’s
another variant.
Reference the contained value
Gets a reference (immutable or mutable) to the contained value.
Dereference the contained value
Dereferences the contained value if it implements Deref
.
Dereferences the contained value mutably if it implements DerefMut
.
Map over the contained value
Applies some function to the contained value.
Applies some function to the contained value, if it’s a local or fatal error.
Applies some function to the contained value, if it’s a local error.
Applies some function to the contained value, if it’s a fatal error.
Iterate over the contained value
iter
iter_mut
into_iter
(forwoah::Result
)into_iter
(for&woah::Result
)into_iter
(for&mut woah::Result
)
Compose Result
s
Unwrap the Result
unwrap
unwrap_err
unwrap_fatal_err
unwrap_local_err
unwrap_or
unwrap_or_default
unwrap_or_else
expect
expect_err
expect_fatal_err
expect_local_err
Copy or clone the contained value
cloned
(for&woah::Result
)cloned
(for&mut woah::Result
)copied
(for&woah::Result
)copied
(for&mut woah::Result
)
Transpose when holding an Option
Convert to and from a std::result::Result
Use woah::Result
with the question mark operator
Try
impl (nightly-only, withnightly
feature ortry_trait
feature)
Use woah::Result
as the return type of main
Termination
impl (nightly-only, withnightly
feature, ortermination_trait
andstd
features)
Build a woah::Result
from an iterator
FromIterator
impl (nightly-only, withnightly
feature, orfrom_iterator_trait
feature)
Features
woah
can be used on stable or nightly. On nightly, enabling the nightly
feature is recommended,
to get the full power of the woah::Result
type, including:
- Being able to use it with the question mark operator,
- Being able to make it the return type of
fn main
, - Gaining a number of useful additional methods, including
from_iter
(which enables easy conversion fromVec<woah::Result<T, L, F>
intowoah::Result<Vec<T>, L, F>
via thecollect
method).
The following table is the full list of features. If you want to use woah
without any dependencies,
you can disable the either_methods
feature, which otherwise imports the either
crate to add additional
methods.
Feature Name | Channels | Depends On | What It Does |
---|---|---|---|
default | Stable, Beta, Nightly | either_methods | Enables default features (currently just either_methods ). |
nightly | Nightly | None | Enables all nightly-only features. This feature is permanently unstable, and changes to the APIs enabled by this feature are never considered breaking changes. |
serde | Stable, Beta, Nightly | None | Implements serde::Serialize and serde::Deserialize for woah::Result . |
std | Stable, Beta, Nightly | None | Use the standard library. Turn off to make the crate no_std compatible. Turning off the standard library conflicts with the termination_trait feature, so turning off std will automatically disable that feature. |
either_methods | Stable, Beta, Nightly | None | Adds the either crate as a dependency and provides convenience methods for operating on Either<LocalErr, FatalErr> . |
Examples
Examples of using woah
on both stable and nightly.
Example on stable
use woah::prelude::*; use std::cmp::Ordering; match get_number() { StdOk(num) => println!("Got a number: {}", num), StdResult::Err(fatal_err) => eprintln!("Fatal error: {:?}", fatal_err), } fn get_number() -> StdResult<i64, FatalError> { // propagate any fatal error let result: StdResult<i64, LocalError> = compare_numbers(5, 5)?; // handle any local error let num = result.unwrap_or_else(|local_err| { println!("Local error: {:?}", local_err); i64::default() }); StdOk(num) } fn compare_numbers(x: i64, y: i64) -> StdResult<StdResult<i64, LocalError>, FatalError> { match x.cmp(&y) { Ordering::Greater => Ok(x), Ordering::Equal => LocalErr(LocalError::SomeError), Ordering::Less => FatalErr(FatalError::CatastrophicError), }.into_result() } #[derive(Debug)] enum LocalError { SomeError, AnotherError } #[derive(Debug)] enum FatalError { BigBadError, CatastrophicError }
Example on nightly
This uses --features nightly
to enable nightly-only features.
use woah::prelude::*; use std::cmp::Ordering; match get_number() { StdOk(num) => println!("Got a number: {}", num), StdResult::Err(fatal_err) => eprintln!("Fatal error: {:?}", fatal_err), } fn get_number() -> StdResult<i64, FatalError> { // propagate any fatal error let result: StdResult<i64, LocalError> = compare_numbers(5, 10)?; // handle any local error let num = result.unwrap_or_else(|local_err| { println!("Local error: {:?}", local_err); i64::default() }); StdOk(num) } fn compare_numbers(x: i64, y: i64) -> Result<i64, LocalError, FatalError> { match x.cmp(&y) { Ordering::Greater => Ok(x), Ordering::Equal => LocalErr(LocalError::Equal), Ordering::Less => FatalErr(FatalError::Less), } } #[derive(Debug)] enum LocalError { Equal } #[derive(Debug)] enum FatalError { Less }