concision_core/macros/
getters.rs1#[macro_export]
7macro_rules! getters {
8 ($($call:ident$(.$field:ident)?<$out:ty>),* $(,)?) => {
9 $($crate::getters!(@impl $call$(.$field)?<$out>);)*
10 };
11 ($via:ident::<[$($call:ident$(.$field:ident)?<$out:ty>),* $(,)?]>) => {
12 $($crate::getters!(@impl $via::$call$(.$field)?<$out>);)*
13 };
14 ($($call:ident$(.$field:ident)?),* $(,)? => $out:ty) => {
15 $($crate::getters!(@impl $call$(.$field)?<$out>);)*
16 };
17 ($via:ident::<[$($call:ident$(.$field:ident)?),* $(,)?]> => $out:ty) => {
18 $crate::getters!($via::<[$($call$(.$field)?<$out>),*]>);
19 };
20
21 (@impl $call:ident<$out:ty>) => {
22 $crate::getters!(@impl $call.$call<$out>);
23 };
24 (@impl $via:ident::$call:ident<$out:ty>) => {
25 $crate::getters!(@impl $via::$call.$call<$out>);
26 };
27 (@impl $call:ident.$field:ident<$out:ty>) => {
28 pub fn $call(&self) -> &$out {
29 &self.$field
30 }
31 paste::paste! {
32 pub fn [< $call _mut>](&mut self) -> &mut $out {
33 &mut self.$field
34 }
35 }
36 };
37 (@impl $via:ident::$call:ident.$field:ident<$out:ty>) => {
38 pub fn $call(&self) -> &$out {
39 &self.$via.$field
40 }
41 paste::paste! {
42 pub fn [< $call _mut>](&mut self) -> &mut $out {
43 &mut self.$via.$field
44 }
45 }
46 };
47}