utils-results 1.1.1

The easiest and most intuitive error handling solution. (no dependencies, about 150 lines pure codes)
Documentation
utils-results-1.1.1 has been yanked.

utils-results

The easiest and most intuitive error handling solution. (no dependencies, about 150 lines pure codes)

Crates.io MIT licensed

| Docs |

Overview

First, You should make your own an error set.

err! {
     BrokenHeader => "broken header."
     AnotherHeader => "not matched header."
     FileNotFound => "file not found."
     EmptyArgument => "empty argument."
     UnexpectedEof => "unexpected eof."
     OutOfBounds => "index out of bounds."
     NotMatched => "btw not matched."
}

And just errbang!

errbang!(err::BrokenHeader)

More Examples

fn foo() -> Result<bool> { // Our Master Result Type
    let bar = 2;
    match bar {
        0 => Ok(true),
        1 => Ok(false),
        _ => errbang!(err::NotMatched, "{} is {}", "bar", bar),
    }
}


fn main() -> Result<()> {
    let _is_bar_zero = foo()?;
}
errbang!(err::MyError1);
errbang!(err::MyError2, "cannot find.");
errbang!(err::MyError3, "{} is {}", "bar", 2);

  • Please use our Master Result<T> and ResultSend<T> instead std::result::Result or io::Result etc..

utils-results/lib.rs
/// Master Result
pub type Result<T> = result::Result<T, Box<dyn error::Error>>;
/// Master Result for Send + Sync trait
pub type ResultSend<T> = result::Result<T, Box<dyn error::Error + Send + Sync>>;

just put this in your project.

pub use utils_results::*;