err-derive 0.1.1

Component storages with arbitrary id spaces
Documentation

err-derive

A failure-like derive macro for the std Error. The source code mostly copied from failure-derive.

Features

  • Derive Display implementation
  • Derive Error implementation (implementing source to return the cause of the error)

Usage

Cargo.toml:

[dependencies]
err-derive = "0.1"

Rust code:

#[macro_use]
extern crate err_derive;

use std::io;

/// `MyError::source` will return a reference to the io_error field
#[derive(Debug, Error)]
#[error(display = "An error occurred.")]
struct MyError {
    #[error(cause)] io_error: io::Error,
}

/// `MyEnumError::source` will return a reference only if it is `Variant2`,
/// otherwise it will return `None`.
#[derive(Debug, Error)]
enum MyEnumError {
    #[error(display = "An error occurred.")]
    Variant1,
    #[error(display = "A different error occurred.")]
    Variant2(#[error(cause)] io::Error),
}

License

This project is dual-licensed under Apache-2.0 / MIT. You're free to choose one of both licenses. Every contribution made to this project is assumed to be licensed according to these terms.

See LICENSE, LICENSE-MIT and LICENSE-APACHE for more information.