failchain
failchain is a tiny companion crate to the failure
crate, which aims to recover the ergonomics of
error_chain. It does this
by bringing back:
chain_err- non-verbose
Error,ErrorKindpairs - support for
bail!andensure!with customErrorKind-s
The failure library recommends three different patterns for errors. This
library implementes the most complex one (and the most useful one) but without all the boilerplate.
What it looks like
// errors.rs
use ;
use Fail;
use PathBuf;
use Result as StdResult;
pub type Error = ; // Use `UnboxedError` instead for
// non-allocating, but bigger `Error`.
pub type Result<T> = ;
// main.rs
use ;
use ;
use File;
use Read;
use Path;
Future Plans
This library is a proof-of-concept and was developed as part of the error_chain ->
failure migration of rust-doom and inspired by
@burntsushi's error handling solution in imdb-rename.
The main issue with the current library is that failchain must be leaked as a public dependency
via the Error type-alias. This would be easily solved with a custom derive which implements the
necessary From and Fail impl-s e.g.
;
// expanding to
The error handling story in Rust is a little up in the air right now, but in my opinion any eventual
solution should include these pieces (as error_chain did).
Versioning
failure is a public dependency of failchain. The library versioning scheme is
<failchain_major><failure_version><failchain_minor>. So 0.1015.2 would be version 0.1.2 of
failchain with a dependency on version 0.1.5 of failure.