@@ -24,18 +24,118 @@ pub(crate) use syn::{
2424 TypeParam , parse_macro_input,
2525} ;
2626
27- /// This is an example of how to use the `Lombok` procedural macro with `get` and `set` attributes.
27+ /// This is an example of how to use the `Lombok` procedural macro with `get` attributes.
2828///
29- /// The `Lombok` procedural macro is used to automatically generate getters and setters for struct fields.
30- /// The `get` attribute controls the visibility of the getter function, and the `set` attribute controls
29+ /// The `Lombok` procedural macro is used to automatically generate getter methods for struct fields.
30+ /// The `get` attribute controls the visibility of the generated getter method.
31+ ///
32+ /// Example:
33+ ///
34+ /// ```rust
35+ /// use lombok_macros::*;
36+ ///
37+ /// #[derive(Getter, Clone)]
38+ /// struct LombokTest2<'a, 'b, T: Clone> {
39+ /// #[get(pub(crate))]
40+ /// list: Vec<String>,
41+ /// #[get(pub(crate))]
42+ /// opt_str_lifetime_a: Option<&'a T>,
43+ /// opt_str_lifetime_b: Option<&'b str>,
44+ /// }
45+ /// let list: Vec<String> = vec!["hello".to_string(), "world".to_string()];
46+ /// let data2: LombokTest2<usize> = LombokTest2 {
47+ /// list: list.clone(),
48+ /// opt_str_lifetime_a: None,
49+ /// opt_str_lifetime_b: None,
50+ /// };
51+ /// let get_list: Vec<String> = data2.get_list().clone();
52+ /// assert_eq!(get_list, list);
53+ /// ```
54+ #[ proc_macro_derive( Getter , attributes( get) ) ]
55+ pub fn getter ( input : TokenStream ) -> TokenStream {
56+ inner_lombok_data ( input, true , false , false )
57+ }
58+
59+ /// This is an example of how to use the `Lombok` procedural macro with `get_mut` attributes.
60+ ///
61+ /// The `Lombok` procedural macro is used to automatically generate mutable getters for struct fields.
62+ /// The `get_mut` attribute controls the visibility of the mutable getter function.
63+ ///
64+ /// Example:
65+ ///
66+ /// ```rust
67+ /// use lombok_macros::*;
68+ ///
69+ /// #[derive(GetterMut, Clone)]
70+ /// struct LombokTest2<'a, 'b, T: Clone> {
71+ /// #[get_mut(pub(crate))]
72+ /// list: Vec<String>,
73+ /// #[get_mut(pub(crate))]
74+ /// opt_str_lifetime_a: Option<&'a T>,
75+ /// opt_str_lifetime_b: Option<&'b str>,
76+ /// }
77+ /// let list: Vec<String> = vec!["hello".to_string(), "world".to_string()];
78+ /// let mut data2: LombokTest2<usize> = LombokTest2 {
79+ /// list: list.clone(),
80+ /// opt_str_lifetime_a: None,
81+ /// opt_str_lifetime_b: None,
82+ /// };
83+ /// let get_list: Vec<String> = data2.get_mut_list().clone();
84+ /// assert_eq!(get_list, list);
85+ /// ```
86+ #[ proc_macro_derive( GetterMut , attributes( get_mut) ) ]
87+ pub fn getter_mut ( input : TokenStream ) -> TokenStream {
88+ inner_lombok_data ( input, false , true , false )
89+ }
90+
91+ /// This is an example of how to use the `Lombok` procedural macro with `set` attributes.
92+ ///
93+ /// The `Lombok` procedural macro is used to automatically generate setters for struct fields.
94+ /// The `set` attribute controls the visibility of the setter function.
95+ ///
96+ /// Example:
97+ ///
98+ /// ```rust
99+ /// use lombok_macros::*;
100+ ///
101+ /// #[derive(Setter, Debug, Clone)]
102+ /// struct LombokTest<'a, 'b, T: Clone> {
103+ /// #[set(pub(crate))]
104+ /// list: Vec<String>,
105+ /// opt_str_lifetime_a: Option<&'a T>,
106+ /// #[set(private)]
107+ /// opt_str_lifetime_b: Option<&'b str>,
108+ /// }
109+ /// let mut data: LombokTest<usize> = LombokTest {
110+ /// list: Vec::new(),
111+ /// opt_str_lifetime_a: None,
112+ /// opt_str_lifetime_b: None,
113+ /// };
114+ /// let list: Vec<String> = vec!["hello".to_string(), "world".to_string()];
115+ /// data.set_list(list.clone());
116+ /// match data.list {
117+ /// left_val => {
118+ /// assert_eq!(*left_val, list);
119+ /// }
120+ /// }
121+ /// ```
122+ #[ proc_macro_derive( Setter , attributes( set) ) ]
123+ pub fn setter ( input : TokenStream ) -> TokenStream {
124+ inner_lombok_data ( input, false , false , true )
125+ }
126+
127+ /// This is an example of how to use the `Lombok` procedural macro with `get`, `get_mut`, and `set` attributes.
128+ ///
129+ /// The `Lombok` procedural macro is used to automatically generate getters, mutable getters, and setters for struct fields.
130+ /// The `get` and `get_mut` attributes control the visibility of the getter functions, while the `set` attribute controls
31131/// the visibility of the setter function.
32132///
33133/// Example:
34134///
35135/// ```rust
36136/// use lombok_macros::*;
37137///
38- /// #[derive(Lombok , Debug, Clone)]
138+ /// #[derive(Data , Debug, Clone)]
39139/// struct LombokTest<'a, 'b, T: Clone> {
40140/// #[get(pub(crate))]
41141/// #[set(pub(crate))]
@@ -45,25 +145,22 @@ pub(crate) use syn::{
45145/// #[set(private)]
46146/// opt_str_lifetime_b: Option<&'b str>,
47147/// }
48- ///
49- /// fn main() {
50- /// let mut data: LombokTest<usize> = LombokTest {
51- /// list: Vec::new(),
52- /// opt_str_lifetime_a: None,
53- /// opt_str_lifetime_b: None,
54- /// };
55- /// let list: Vec<String> = vec!["hello".to_string(), "world".to_string()];
56- /// data.set_list(list.clone());
57- /// match data.get_list() {
58- /// left_val => {
59- /// assert_eq!(*left_val, list);
60- /// }
148+ /// let mut data: LombokTest<usize> = LombokTest {
149+ /// list: Vec::new(),
150+ /// opt_str_lifetime_a: None,
151+ /// opt_str_lifetime_b: None,
152+ /// };
153+ /// let list: Vec<String> = vec!["hello".to_string(), "world".to_string()];
154+ /// data.set_list(list.clone());
155+ /// match data.get_list() {
156+ /// left_val => {
157+ /// assert_eq!(*left_val, list);
61158/// }
62159/// }
63160/// ```
64- #[ proc_macro_derive( Lombok , attributes( set, get, get_mut) ) ]
65- pub fn lombok_data ( input : TokenStream ) -> TokenStream {
66- inner_lombok_data ( input)
161+ #[ proc_macro_derive( Data , attributes( set, get, get_mut) ) ]
162+ pub fn data ( input : TokenStream ) -> TokenStream {
163+ inner_lombok_data ( input, true , true , true )
67164}
68165
69166/// A procedural macro that implements the `std::fmt::Display` trait for a type,
0 commit comments