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

#181 in Procedural macros

Download history 22710/week @ 2024-10-23 19131/week @ 2024-10-30 18688/week @ 2024-11-06 18962/week @ 2024-11-13 20188/week @ 2024-11-20 20920/week @ 2024-11-27 20980/week @ 2024-12-04 19876/week @ 2024-12-11 16273/week @ 2024-12-18 5748/week @ 2024-12-25 13205/week @ 2025-01-01 17378/week @ 2025-01-08 20751/week @ 2025-01-15 21601/week @ 2025-01-22 23581/week @ 2025-01-29 16925/week @ 2025-02-05

86,235 downloads per month
Used in 87 crates (52 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
~37K SLoC