outcome

Crates.iooutcome
lib.rsoutcome
version0.1.7
sourcesrc
created_at2017-10-20 02:59:51.497046
updated_at2017-10-22 17:21:19.182628
descriptionA Success/Failure type for rust
homepage
repositoryhttps://github.com/lachlansneff/outcome-rust.git
max_upload_size
id36280
size8,474
Lachlan Sneff (lachlansneff)

documentation

https://docs.rs/outcome/

README

Build Status Latest Version

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_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!"),
}
Commit count: 21

cargo fmt