You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
Magic_RB 050018fea3 Merge pull request 'documented few functions' (#1) from ThyW/e-error:master into master 3 weeks ago
src documented few functions 3 weeks ago
.gitignore Initial commit 4 weeks ago
Cargo.toml Cargo.toml: features mimicking std, lib.rs: EResult methods mimicking std 3 weeks ago
LICENSE Initial commit 4 weeks ago
README.md README.md: crate to e_error 3 weeks ago

README.md

E-Error

E-Error is a Rust crate, which implements a split Error handling mechanism. Specifically, it splits all errors into two kinds, internal and external errors. This distinction allows you to easily handle internal erros and user gateways, as any internal error, which is not supposed to be exposed to the user, can be easily converted into a generic external error.

Basic Usage

This is what's required to setup E-Error, crate two enums representing your internal and external errors, implement traits and finally merge into one EResult you can use everywhere.

#[derive(Debug)]
pub enum InErr {
    // stuff
}

impl e_error::InErr for InErr {
    // reports are like maps, except that they automatically call these Fns when the EResult is not Ok. Comes in useful when working with async code

    fn report(self, cause: Box<dyn std::error::Error + Send>, backtrace: std::backtrace::Backtrace) {
        // place some report handling here
    }
}

#[derive(Debug)]
pub enum ExtErr {
    // stuff
}

impl e_error::ExtErr for ExtErr {
    fn report(self) {
	    // here too
    }
}

type EResult<O> = e_error::EResult<O, InErr, ExtErr>;

Then use it like so.

use std::io::Error as ioError;
use std::io::ErrorKind as ioErrorKind;

let res: Result<String, ioError> = Err(ioError::new(ioErrorKind::ConnectionRefused, String::new()));

let wrapped: EResult<String> = res.internal(InErr::ConnectionRefused);