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
//! Macros for reducing builder boilerplate.
//!
//! This module provides macros that generate common builder patterns,
//! reducing code duplication and ensuring consistency across all builders.
/// Generates a scalar field setter method.
///
/// Creates a setter method that takes ownership of `self`, sets a field to `Some(value)`,
/// and returns `self` for method chaining.
///
/// # Arguments
///
/// * `$field` - The field name
/// * `$type` - The field type
/// * `$doc` - Documentation string for the setter
///
/// # Examples
///
/// ```ignore
/// impl MessageBuilder {
/// builder_setter!(id, u32, "Sets the CAN message ID");
/// }
///
/// // Expands to:
/// // /// Sets the CAN message ID
/// // #[must_use = "builder method returns modified builder"]
/// // pub fn id(mut self, id: u32) -> Self {
/// // self.id = Some(id);
/// // self
/// // }
/// ```
/// Generates a string field setter method.
///
/// Creates a setter method that accepts `impl AsRef<str>`, converts it to `String`,
/// wraps it in `Some`, and returns `self` for method chaining.
///
/// # Arguments
///
/// * `$field` - The field name
/// * `$doc` - Documentation string for the setter
///
/// # Examples
///
/// ```ignore
/// impl MessageBuilder {
/// builder_string_setter!(name, "Sets the message name");
/// }
///
/// // Expands to:
/// // /// Sets the message name
/// // #[must_use = "builder method returns modified builder"]
/// // pub fn name(mut self, name: impl AsRef<str>) -> Self {
/// // self.name = Some(name.as_ref().to_string());
/// // self
/// // }
/// ```