1 unstable release

Uses old Rust 2015

0.1.0 May 12, 2016

#21 in #err

MIT/Apache

7KB
90 lines

Adds a parse method to Result

Example

extern crate parse_result;
use parse_result::*;
use std::env;

fn main() {
    // It turns code like this:
    env::var("PORT").map(|s| s.parse().unwrap_or(3000)).unwrap_or(3000);

    // Into this:
    env::var("PORT").parse().unwrap_or(3000);

    // Matching to find the specific failure
    match env::var("PORT").parse::<u32>() {
        Ok(port) => println!("Parsed port {} successfully!", port),
        Err(OriginalErr(e)) => panic!("Failed to get PORT from env: {}", e),
        Err(ParseFailure(e)) => panic!("Failed to parse PORT: {}", e),
    }
}

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps