Crates.io | small_derive_deref |
lib.rs | small_derive_deref |
version | 0.1.3 |
source | src |
created_at | 2024-08-07 11:05:20.539713 |
updated_at | 2024-08-10 20:21:18.769544 |
description | Derive the Deref and DerefMut traits |
homepage | |
repository | https://github.com/Ike-l/derive_deref |
max_upload_size | |
id | 1328298 |
size | 9,204 |
This crate adds #[derive(Deref)]
#[derive(DerefMut]
.
It works for:
#[DerefTarget]
/ #[DerefMutTarget]
.#[DerefTarget]
and #[DerefMutTarget]
must be the sameuse std::ops::DerefMut;
use small_derive_deref::{Deref, DerefMut};
#[derive(Deref, DerefMut)]
struct WrapperStructDifferentTargetsGenerics<'a> {
#[DerefTarget]
field: &'a str,
#[DerefMutTarget]
field_mut: &'a str,
}
let mut w = WrapperStructDifferentTargetsGenerics { field: "not rust", field_mut: "rust"};
*w = "rUst";
assert_eq!(*w, "not rust");
assert_eq!(*w.deref_mut(), "rUst");
#[derive(Deref, DerefMut)]
struct WrapperTuple(i32, i32);
let mut w = WrapperTuple(1, 3);
*w *= 2;
assert_eq!(*w, 2);
assert_eq!(*w.deref_mut(), 2);
MIT or Apache-2.0