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

#133 in Procedural macros

Download history 12036/week @ 2024-06-12 10889/week @ 2024-06-19 10528/week @ 2024-06-26 11268/week @ 2024-07-03 11496/week @ 2024-07-10 13408/week @ 2024-07-17 12905/week @ 2024-07-24 13851/week @ 2024-07-31 12403/week @ 2024-08-07 11944/week @ 2024-08-14 12625/week @ 2024-08-21 15577/week @ 2024-08-28 15830/week @ 2024-09-04 16458/week @ 2024-09-11 15572/week @ 2024-09-18 15923/week @ 2024-09-25

67,176 downloads per month
Used in 79 crates (46 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

~1.5MB
~35K SLoC