Setter

Derive Macro Setter 

Source
#[derive(Setter)]
{
    // Attributes available to this derive:
    #[set]
}
Expand description

This is an example of how to use the Lombok procedural macro with set attributes.

The Lombok procedural macro is used to automatically generate setters for struct fields. The set attribute controls the visibility of the setter function.

Example:

use lombok_macros::*;

#[derive(Setter, Debug, Clone)]
struct LombokTest<'a, 'b, T: Clone> {
    #[set(pub(crate))]
    list: Vec<String>,
    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.list {
    left_val => {
        assert_eq!(*left_val, list);
    }
}