lombok_macros/
lib.rs

1use proc_macro::TokenStream;
2pub(crate) mod cfg;
3pub(crate) mod func;
4pub(crate) mod generate;
5pub(crate) mod parse;
6pub(crate) mod visibility;
7use generate::func::inner_lombok_data;
8
9/// This is an example of how to use the `Lombok` procedural macro with `get` and `set` attributes.
10///
11/// The `Lombok` procedural macro is used to automatically generate getters and setters for struct fields.
12/// The `get` attribute controls the visibility of the getter function, and the `set` attribute controls
13/// the visibility of the setter function.
14///
15/// Example:
16///
17/// ```rust
18/// use lombok_macros::*;
19///
20/// #[derive(Lombok, Debug, Clone)]
21/// struct LombokTest<'a, 'b, T: Clone> {
22///     #[get(pub(crate))]
23///     #[set(pub(crate))]
24///     list: Vec<String>,
25///     #[get(pub(crate))]
26///     opt_str_lifetime_a: Option<&'a T>,
27///     #[set(private)]
28///     opt_str_lifetime_b: Option<&'b str>,
29/// }
30///
31/// fn main() {
32///     let mut data: LombokTest<usize> = LombokTest {
33///         list: Vec::new(),
34///         opt_str_lifetime_a: None,
35///         opt_str_lifetime_b: None,
36///     };
37///     let list: Vec<String> = vec!["hello".to_string(), "world".to_string()];
38///     data.set_list(list.clone());
39///     match data.get_list() {
40///         left_val => {
41///             assert_eq!(*left_val, list);
42///         }
43///     }
44/// }
45/// ```
46#[proc_macro_derive(Lombok, attributes(set, get, get_mut))]
47pub fn lombok_data(input: TokenStream) -> TokenStream {
48    inner_lombok_data(input)
49}