macro_rules! gsw {
($($name:ident: &$T:ty),* $(,)?) => { ... };
($($name:ident: $T:ty),* $(,)?) => { ... };
(@setter $name:ident: $T:ty) => { ... };
(@get $name:ident: &$T:ty) => { ... };
(@get $name:ident: $T:ty) => { ... };
(@get_mut $name:ident: $T:ty) => { ... };
(@set $name:ident: $T:ty) => { ... };
(@with $name:ident: $T:ty) => { ... };
}Expand description
The gsw macro generates getter and setter methods for the fields of a struct.
ยงUsage
#[derive(Clone, Debug, Default)]
pub struct Sample {
pub(crate) a: usize,
pub(crate) b: std::collections::HashMap<String, usize>,
}
impl Sample {
scsys_core::gsw! {
a: usize,
}
scsys_core::gsw! {
b: &std::collections::HashMap<String, usize>,
}
}
#[test]
fn _sampler() {
let mut sample = Sample::default().with_a(10);
assert_eq!(sample.a(), 10);
assert_eq!(sample.a_mut(), &mut 10);
assert_eq!(sample.set_a(20).a(), 20);
}