Expand description
§The outcome crate
Type Outcome represents a success or failure: Every Outcome is either Success or Failure
use outcome::*;
fn do_something() -> Outcome {
Success
}
// The return value is an outcome
let result = do_something();
// Pattern Match
match result {
Success => println!("Well done!"),
Failure => println!("Oh well :("),
}§Examples
Using and_then on an Outcome:
use outcome::*;
// Returns `Failure`
let result = Outcome::from(false);
match result.and_then(|| Success) {
Success => println!("Success! :)"),
Failure => println!("Failure :("),
}Using or_none on an Outcome to transform it into an Option:
use outcome::*;
let result = Success;
// Encapsulates arg within an option
match result.or_none("hello!") {
Some(s) => println!("{}", s),
None => println!("Nothing here!"),
}