11 releases

0.1.8 Oct 16, 2024
0.1.7 Oct 15, 2024
0.1.6 Jul 27, 2023
0.1.5 Mar 4, 2023
0.0.2 Sep 25, 2022

#141 in Development tools

Download history 91505/week @ 2024-08-22 101969/week @ 2024-08-29 120312/week @ 2024-09-05 112128/week @ 2024-09-12 124280/week @ 2024-09-19 137776/week @ 2024-09-26 128918/week @ 2024-10-03 137091/week @ 2024-10-10 158433/week @ 2024-10-17 148945/week @ 2024-10-24 144433/week @ 2024-10-31 140376/week @ 2024-11-07 188600/week @ 2024-11-14 155958/week @ 2024-11-21 158480/week @ 2024-11-28 144040/week @ 2024-12-05

674,627 downloads per month
Used in 923 crates (4 directly)

MIT/Apache

42KB
784 lines

impl-more

Concise trait implementations.

crates.io Documentation MIT or Apache 2.0 licensed
dependency status Download CircleCI

Usage

struct MyNewTypeStruct(String);

impl_more::impl_as_ref!(MyNewTypeStruct => String);
impl_more::impl_as_mut!(MyNewTypeStruct => String);

impl_more::impl_deref!(MyNewTypeStruct => String);
impl_more::impl_deref_mut!(MyNewTypeStruct);
// or, to deref through String too:
// impl_more::forward_deref_and_mut!(MyNewTypeStruct, ref str);

impl_more::impl_from!(String => MyNewTypeStruct);
impl_more::impl_into!(MyNewTypeStruct => String);

enum MyEnum {
    Bar,
    Qux,
}

impl_more::impl_display_enum!(MyEnum, Bar => "bar", Qux => "qux");

enum Coords {
    Xy(i64, i64),
    Xyz(i64, i64, i64),
}

impl_more::impl_display_enum!(
    Coords,
    Xy(x, y) => "{x}, {y}",
    Xyz(x, y, z) => "{x}, {y}, {z}",
);

#[derive(Debug)]
struct MyError(eyre::Report);

impl_more::forward_display!(MyError);
impl_more::forward_error!(MyError);

let err = MyError(eyre::eyre!("something went wrong"));
assert_eq!(err.source().unwrap().to_string(), "something went wrong");

#[derive(Debug)]
enum Err {
    Io(std::io::Error),
    Generic(String),
}

impl_more::impl_display_enum!(Err, Io(err) => "{err}", Generic(msg) => "{msg}");
impl_more::impl_error_enum!(Err, Io(err) => err);

No runtime deps