| Crates.io | error-chain-mini |
| lib.rs | error-chain-mini |
| version | 0.2.0 |
| created_at | 2018-04-19 07:31:06.478227+00 |
| updated_at | 2018-05-25 05:39:54.384454+00 |
| description | error-chain for minimalist |
| homepage | |
| repository | https://github.com/kngwyu/error-chain-mini |
| max_upload_size | |
| id | 61363 |
| size | 41,180 |
I think error-chain is good, especially I love chain_err method.
However, sometimes I feel it too complex.
I don't want to generate ResultExt and ChainedError by macro. Isn't it confusing?
So, I made this tiny library, providing very straight forward implementation of
ResultExt, ChainedError, and some related traits.
In addition, You can use derive to implement your own ErrorKind type.
extern crate error_chain_mini;
#[macro_use]
extern crate error_chain_mini_derive;
use std::io;
use error_chain_mini::*;
use std::error::Error;
#[derive(ErrorKind)]
enum MyErrorKind {
#[msg(short = "io error", detailed = "inner: {:?}", _0)]
IoError(io::Error),
#[msg(short = "index error", detailed = "invalid index: {:?}", _0)]
IndexEroor(usize),
TrivialError,
}
type MyError = ChainedError<MyErrorKind>;
type MyResult<T> = Result<T, MyError>;
fn always_fail() -> MyResult<()> {
Err(MyErrorKind::TrivialError.into_with("Oh my god!"))
}
fn main() {
assert_eq!("index error invalid index: 10", MyErrorKind::IndexEroor(10).full());
let chained = always_fail().chain_err("Error in main()");
assert!(chained.is_err());
if let Err(chained) = chained {
assert_eq!(chained.description(), "MyErrorKind::TrivialError");
assert_eq!(chained.context[0], "Oh my god!");
assert_eq!(chained.context[1], "Error in main()");
}
}
1.26.0 (match_default_bindings is needed)
This project is licensed under either of
at your option.