1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
use TokenStream;
use ;
use do_make_builder_setters;
use do_make_basic_setters;
/// Generates builder-style setter methods for struct fields, enabling
/// a fluent, chainable API for struct initialization. Each setter
/// follows the pattern `<prefix>_<suffix>` (default: `with_<field_name>`),
/// accepts any type implementing `Into<T>` (where `T` is the field type),
/// and returns a modified instance.
///
/// Apply this macro to a struct with named fields using
/// `#[make_builder_setters]`. The original struct remains unchanged,
/// and setters provide a convenient way to set field values in a
/// chainable manner.
///
/// Multiple `#[builder_setter]` attributes can be applied to a
/// single field, generating multiple setter methods with the specified
/// configurations.
///
/// ### Customization Options
/// - `#[disable_builder_setters]`: Skip setters generation for a
/// specific field.
///
/// - `#[builder_setter(
/// name = "<name>",
/// visibility = "<vis>",
/// prefix = "<prefix>",
/// suffix = "<suffix>",
/// with_into = true|false,
/// )]`:
///
/// Configure the setter with the following options:
/// - `name`: Set a custom method name, overriding prefix/suffix.
/// - `visibility`: Override method visibility. Set to "" for
/// `pub(self)`. Default: `pub`.
/// - `prefix`: Override the prefix. Default: "with".
/// - `suffix`: Override the suffix. Default: field name.
/// - `with_into`: Whether to use the `impl Into<T>` in method
/// parameters. Default: true.
///
/// # Example
/// ```rust
/// use useless_setter_maker::make_builder_setters;
///
/// #[make_builder_setters]
/// #[derive(Debug, PartialEq, Default)]
/// struct Foo {
/// bar: u16,
///
/// #[builder_setter(prefix = "set", visibility = "pub")]
/// #[builder_setter(name = "install_baz", visibility = "pub(crate)")]
/// baz: String,
///
/// #[disable_builder_setters]
/// foobar: bool,
///
/// #[builder_setter(suffix = "fb", visibility = "pub(crate)")]
/// foobaz: bool,
///
/// #[builder_setter(prefix = "provide", suffix = "bb")]
/// barbaz: String,
///
/// #[builder_setter(name = "install_bazfoo", visibility = "")]
/// bazfoo: String,
///
/// #[builder_setter(with_into = false)]
/// bazbaz: Option<String>,
/// }
///
/// let foo = Foo::default()
/// .with_bar(100 as u16) // Pub
/// .set_baz("some_text") // Pub, first baz setter
/// .install_baz("some_text") // Pub(crate), second baz setter
/// .with_fb(true) // Pub(crate)
/// .provide_bb("other_text") // Pub
/// .install_bazfoo("bazfoo") // Pub(self)
/// .with_bazbaz(String::from("some_text")); // Pub
///
/// let expected = Foo {
/// bar: 100,
/// baz: String::from("some_text"),
/// foobar: false,
/// foobaz: true,
/// barbaz: String::from("other_text"),
/// bazfoo: String::from("bazfoo"),
/// bazbaz: Some(String::from("some_text")),
/// };
///
/// assert_eq!(foo, expected);
/// ```
/// Generates basic setter methods for struct fields. Each setter
/// follows the pattern `<prefix>_<suffix>` (default: `set_<field_name>`),
/// accepts any type implementing `Into<T>` (where `T` is the field type),
/// and returns a modified instance.
///
/// Apply this macro to a struct with named fields using
/// `#[make_basic_setters]`. The original struct remains unchanged,
/// and setters provide a convenient way to set field values..
///
/// Multiple `#[basic_setter]` attributes can be applied to a
/// single field, generating multiple setter methods with the specified
/// configurations.
///
/// ### Customization Options
/// - `#[disable_basic_setters]`: Skip setters generation for a
/// specific field.
///
/// - `#[basic_setter(
/// name = "<name>",
/// visibility = "<vis>",
/// prefix = "<prefix>",
/// suffix = "<suffix>",
/// with_into = true|false,
/// )]`:
///
/// Configure the setter with the following options:
/// - `name`: Set a custom method name, overriding prefix/suffix.
/// - `visibility`: Override method visibility. Set to "" for
/// `pub(self)`. Default: `pub`.
/// - `prefix`: Override the prefix. Default: "set".
/// - `suffix`: Override the suffix. Default: field name.
/// - `with_into`: Whether to use the `impl Into<T>` in method
/// parameters. Default: true.
///
/// # Example
/// ```rust
/// use useless_setter_maker::make_basic_setters;
///
/// #[make_basic_setters]
/// #[derive(Debug, PartialEq, Default)]
/// struct Foo {
/// bar: u16,
///
/// #[basic_setter(prefix = "with", visibility = "pub")]
/// #[basic_setter(name = "install_baz", visibility = "pub(crate)")]
/// baz: String,
///
/// #[disable_basic_setters]
/// foobar: bool,
///
/// #[basic_setter(suffix = "fb", visibility = "pub(crate)")]
/// foobaz: bool,
///
/// #[basic_setter(prefix = "provide", suffix = "bb")]
/// barbaz: String,
///
/// #[basic_setter(name = "install_bazfoo", visibility = "")]
/// bazfoo: String,
///
/// #[basic_setter(with_into = false)]
/// bazbaz: Option<String>,
/// }
///
/// let mut foo = Foo::default();
///
/// foo.set_bar(100 as u16); // Pub
/// foo.with_baz("some_text"); // Pub, first baz setter
/// foo.install_baz("some_text"); // Pub(crate), second baz setter
/// foo.set_fb(true); // Pub(crate)
/// foo.provide_bb("other_text"); // Pub
/// foo.install_bazfoo("bazfoo"); // Pub(self)
/// foo.set_bazbaz(String::from("some_text")); // Pub
///
/// let expected = Foo {
/// bar: 100,
/// baz: String::from("some_text"),
/// foobar: false,
/// foobaz: true,
/// barbaz: String::from("other_text"),
/// bazfoo: String::from("bazfoo"),
/// bazbaz: Some(String::from("some_text")),
/// };
///
/// assert_eq!(foo, expected);
/// ```