gsw

Macro gsw 

Source
macro_rules! gsw {
    ($($name:ident: &$T:ty),* $(,)?) => { ... };
    ($($name:ident: $T:ty),* $(,)?) => { ... };
    (@get $name:ident: &$T:ty) => { ... };
    (@get $name:ident: $T:ty) => { ... };
    (@get_mut $name:ident: $T:ty) => { ... };
    (@setter $name:ident: $T:ty) => { ... };
}
Expand description

The gsw macro generates getter and setter methods for the fields of a struct. At the moment, the macro can handle any type; for types that implement the Copy trait, simply drop the & to the left of each type.

Note: make sure that

ยงUsage

use scsys_core::gsw;

#[derive(Clone, Debug, Default)]
pub struct Sample<T> {
    pub(crate) a: usize,
    pub(crate) b: f32,
    pub(crate) store: Vec<u8>,
    pub(crate) c:T,

}

impl<T> Sample<T> {
    gsw! {
        a: usize,
        b: f32,
    }
    gsw! {
        c: &T,
        store: &Vec<u8>,
    }
}

#[test]
fn test_sample_gsw_impls() {
    let mut sample = Sample::<&str>::default().with_a(10).with_store(vec![1, 2, 3]);
    sample.set_b(3.14).set_c("hello");
    assert_eq!(sample.a(), 10);
    assert_eq!(sample.b(), 3.14);
    assert_eq!(sample.c(), "hello");
    assert_eq!(sample.store(), &vec![1, 2, 3]);
    sample.c_mut().push(u8::MAX);
    assert!(sample.store().last() == Some(&u8::MAX));
}