Crates.io | derive_deref |
lib.rs | derive_deref |
version | 1.1.1 |
source | src |
created_at | 2018-01-15 18:57:09.91206 |
updated_at | 2020-06-28 12:13:38.396404 |
description | Adds `#[derive(Deref)]` and `#[derive(DerefMut)]` |
homepage | |
repository | https://github.com/sgrif/derive_deref |
max_upload_size | |
id | 46966 |
size | 20,310 |
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.
#[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"));
Licensed under either of these:
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.