summaryrefslogtreecommitdiff
path: root/src/util.rs
blob: 309a471ef36a3955ce0dd46142bfe627a39022c0 (plain)
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
macro_rules! enum_with_get_inner {
    (
       inner = $inner: ty;
        $(#[$attr: meta])*
        $visibility: vis enum $enum_name: ident {
            $(
                $(#[$variant_attr: meta])*
                $variant: ident($variant_inner: ty),
            )*
        }
    ) => {
        $(#[$attr])*
        $visibility enum $enum_name {
            $(
                $(#[$variant_attr])*
                $variant($inner)
            ),*
        }

        impl $enum_name {
            /// Returns the inner value.
            #[must_use]
            pub fn inner(&self) -> &$inner {
                match self {
                    $(
                        $enum_name::$variant(inner) => inner
                    ),*
                }
            }
        }
    };
}

pub(crate) use enum_with_get_inner;