| Crates.io | outcome |
| lib.rs | outcome |
| version | 0.1.7 |
| created_at | 2017-10-20 02:59:51.497046+00 |
| updated_at | 2017-10-22 17:21:19.182628+00 |
| description | A Success/Failure type for rust |
| homepage | |
| repository | https://github.com/lachlansneff/outcome-rust.git |
| max_upload_size | |
| id | 36280 |
| size | 8,474 |
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 :("),
}
Using and_then on an Outcome:
/use outcome::*;
// Returns `Failure`
let result = Outcome::from_bool(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!"),
}