1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/// A helper to implement `Deref` for a type.
#[macro_export]
macro_rules! deref {
    ($ty:ident $(<$($generic:ident),*>)? => $field:tt: $target:ty) => {
        impl $(<$($generic),*>)? ::core::ops::Deref for $ty $(<$($generic),*>)? {
            type Target = $target;

            fn deref(&self) -> &Self::Target {
                &self.$field
            }
        }
    };
}

/// A helper to implement `DerefMut` for a type.
#[macro_export]
macro_rules! deref_mut {
    ($ty:ident $(<$($generic:ident),*>)? => $field:tt) => {
        impl $(<$($generic),*>)? ::core::ops::DerefMut for $ty $(<$($generic),*>)? {
            fn deref_mut(&mut self) -> &mut Self::Target {
                &mut self.$field
            }
        }
    };
}

/// A helper to implement `From` for a unit struct.
#[macro_export]
macro_rules! from {
    ($from:ty => $ty:ident $(<$($generic:ident),*>)?) => {
        impl $(<$($generic),*>)? ::core::convert::From<$from> for $ty $(<$($generic),*>)? {
            fn from(from: $from) -> Self {
                Self(from)
            }
        }
    };
}

#[allow(unused_imports)]
pub(crate) use crate::{deref, deref_mut, from};