[go: up one dir, main page]

easy-ext 0.1.7

An attribute macro for easily writing extension trait pattern.
Documentation

easy-ext

crates-badge docs-badge license-badge rustc-badge

An attribute macro for easily writing extension trait pattern.

Documentation

Usage

Add this to your Cargo.toml:

[dependencies]
easy-ext = "0.1"

The current easy-ext requires Rust 1.31 or later.

Examples

use easy_ext::ext;

#[ext(ResultExt)]
impl<T, E> Result<T, E> {
    fn err_into<U>(self) -> Result<T, U>
    where
        E: Into<U>,
    {
        self.map_err(Into::into)
    }
}

Code like this will be generated:

trait ResultExt<T, E> {
    fn err_into<U>(self) -> Result<T, U>
    where
        E: Into<U>;
}

impl<T, E> ResultExt<T, E> for Result<T, E> {
    fn err_into<U>(self) -> Result<T, U>
    where
        E: Into<U>,
    {
        self.map_err(Into::into)
    }
}

You can elide the trait name. Note that in this case, #[ext] assigns a random name, so you cannot import/export the generated trait.

use easy_ext::ext;

#[ext]
impl<T, E> Result<T, E> {
    fn err_into<U>(self) -> Result<T, U>
    where
        E: Into<U>,
    {
        self.map_err(Into::into)
    }
}

Supported items

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.