#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

#79 in Rust patterns

Download history 47/week @ 2019-03-28 1012/week @ 2019-04-04 19/week @ 2019-04-11 122/week @ 2019-04-18 118/week @ 2019-04-25 176/week @ 2019-05-02 258/week @ 2019-05-09 397/week @ 2019-05-16 157/week @ 2019-05-23 261/week @ 2019-05-30 305/week @ 2019-06-06 3598/week @ 2019-06-13 3449/week @ 2019-06-20 1495/week @ 2019-06-27 874/week @ 2019-07-04

912 downloads per month
Used in 27 crates (5 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
~25K SLoC