Crate small_derive_deref

Crate small_derive_deref 

Source
Expand description

§Example

use std::ops::DerefMut;
use small_derive_deref::{Deref, DerefMut};
 
#[derive(Deref, DerefMut)]
struct WrapperStructDifferentTargetsMultipleGenerics<'a, T> {
    #[DerefTarget]
    field: &'a str,
    #[DerefMutTarget]
    field_mut: &'a str,
    foo: T
}
 
let mut w = WrapperStructDifferentTargetsMultipleGenerics { field: "not rust", field_mut: "rust", foo: "foo"};
assert_eq!(*w, "not rust");
*w = "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);

Derive Macros§

Deref
Defines Deref either on a struct or a tuple.
No attribute needed for structs with one field or tuples.
DerefMut
Defines DerefMut either on a struct or a tuple.
No attribute needed for structs with one field or tuples.