#[derive(Data)]
{
// Attributes available to this derive:
#[set]
#[get]
#[get_mut]
}
Expand description
This is an example of how to use the Lombok procedural macro with get, get_mut, and set attributes.
The Lombok procedural macro is used to automatically generate getters, mutable getters, and setters for struct fields.
The get and get_mut attributes control the visibility of the getter functions, while the set attribute controls
the visibility of the setter function.
Example:
use lombok_macros::*;
#[derive(Data, Debug, Clone)]
struct LombokTest<'a, 'b, T: Clone> {
#[get(pub(crate))]
#[set(pub(crate))]
list: Vec<String>,
#[get(pub(crate))]
opt_str_lifetime_a: Option<&'a T>,
#[set(private)]
opt_str_lifetime_b: Option<&'b str>,
}
let mut data: LombokTest<usize> = LombokTest {
list: Vec::new(),
opt_str_lifetime_a: None,
opt_str_lifetime_b: None,
};
let list: Vec<String> = vec!["hello".to_string(), "world".to_string()];
data.set_list(list.clone());
match data.get_list() {
left_val => {
assert_eq!(*left_val, list);
}
}