#derive #deref

macro derive_deref

Adds #[derive(Deref)] and #[derive(DerefMut)]

5 stable releases

Uses old Rust 2015

1.1.1 Jun 28, 2020
1.1.0 Jun 9, 2019
1.0.2 Jan 27, 2019
1.0.1 Apr 10, 2018
1.0.0 Jan 15, 2018

#333 in Rust patterns

Download history 2956/week @ 2021-09-26 3010/week @ 2021-10-03 3181/week @ 2021-10-10 3056/week @ 2021-10-17 2578/week @ 2021-10-24 1894/week @ 2021-10-31 2200/week @ 2021-11-07 2187/week @ 2021-11-14 1735/week @ 2021-11-21 2117/week @ 2021-11-28 2529/week @ 2021-12-05 2222/week @ 2021-12-12 1302/week @ 2021-12-19 658/week @ 2021-12-26 1948/week @ 2022-01-02 2403/week @ 2022-01-09

6,398 downloads per month
Used in 41 crates (15 directly)

MIT/Apache

7KB
83 lines

derive_deref

This crate adds a simple #[derive(Deref)] and #[derive(DerefMut)]. It can be used on any struct with exactly one field. If the type of that field is a reference, the reference will be returned directly.

Example

#[derive(Deref)]
struct MyInt(i32);

assert_eq!(&1, &*MyInt(1));
assert_eq!(&2, &*MyInt(2));

#[derive(Deref)]
struct MyString<'a>(&'a str);

// Note that we deref to &str, not &&str
assert_eq!("foo", &*MyString("foo"));
assert_eq!("bar", &*MyString("bar"));

License

Licensed under either of these:

Contributing

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

Dependencies

~285–700KB
~17K SLoC

r^