7 releases

Uses old Rust 2015

0.1.7 Oct 22, 2017
0.1.6 Oct 20, 2017

37 downloads per month
Used in bitboard_xo

MIT license

8KB
64 lines

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!"),
}

No runtime deps