Macro Deref
macro_rules! Deref { ... }
Using #[derive(Deref)]
Deriving Deref only works for a single field of a struct.
It's possible to use it in two ways:
- Dereferencing to the field, i.e. like if your type was a reference type.
- Doing a dereference on the field, for when the field itself is a reference type like
&andBox.
With #[deref] or #[deref(ignore)] it's possible to indicate the field that
you want to derive Deref for.
Example usage
# use Deref;
#
;
// You can specify the field you want to derive `Deref` for.
let num = Num;
let boxed = MyBoxedInt;
let cool_vec = CoolVec;
assert_eq!;
assert_eq!;
assert_eq!;
Structs
When deriving a non-forwarded Deref for a struct:
# use Deref;
#
Code like this will be generated:
#
When deriving a forwarded Deref for a struct:
# use Deref;
#
;
Code like this will be generated:
# ;
Enums
Deriving Deref is not supported for enums.