dd
derive_deref
cargo install derive_deref
dd

derive_deref

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

by Sage Griffin

1.1.1 (see all)License:MIT OR Apache-2.0
cargo install derive_deref
Readme

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.

GitHub Stars

32

LAST COMMIT

2yrs ago

MAINTAINERS

2

CONTRIBUTORS

4

OPEN ISSUES

2

OPEN PRs

1
VersionTagPublished
1.1.1
2yrs ago
1.1.0
3yrs ago
1.0.2
3yrs ago
1.0.1
4yrs ago
No alternatives found
No tutorials found
Add a tutorial