#derive #deref

macro derive_deref

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

4 stable releases

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

#28 in #derive

Download history 1403/week @ 2019-11-01 988/week @ 2019-11-08 1749/week @ 2019-11-15 1681/week @ 2019-11-22 1434/week @ 2019-11-29 914/week @ 2019-12-06 984/week @ 2019-12-13 670/week @ 2019-12-20 464/week @ 2019-12-27 766/week @ 2020-01-03 1660/week @ 2020-01-10 1505/week @ 2020-01-17 2560/week @ 2020-01-24 2188/week @ 2020-01-31 4142/week @ 2020-02-07

5,298 downloads per month
Used in 30 crates (10 directly)

MIT/Apache

7KB
84 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

~1MB
~28K SLoC