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
use add_traits_to_generics;
use TokenStream;
use ;
use *;
/// Derive macro `Builder` generates an **immutable builder** for a struct.
///
/// This macro creates a chainable API for setting each field.
/// Once all fields are set, `.build()` validates and returns `Result<Self, &str>`.
///
/// ### Supported field attributes:
///
/// - `#[set(value = "...")]`
/// Sets a default value for the field when calling `Struct::new()`.
/// If omitted, the field will use the default from `Default::default()`.
///
/// - `#[range(min = x, max = y, err = "...")]`
/// Adds compile-time generated range validation (numeric types only).
///
/// - `#[build(pattern = "...", err = "...")]`
/// Applies regex validation to the field on `.build()`.
///
/// - `#[skip_trait]`
/// Prevents automatic implementation of helper traits.
///
/// ### Example:
///
/// ```rust
/// use kenzu::Builder;
///
/// #[derive(Builder)]
/// pub struct User {
/// pub id: String,
/// #[set(value = "default_name")]
/// pub name: String,
/// #[build(pattern = r"^.+@.+\..+$", err = "invalid email")]
/// pub email: String,
/// #[range(min = 18, max = 99, err = "invalid age")]
/// pub age: u8,
/// }
///
/// let user = User::new()
/// .id("001")
/// .name("Alice")
/// .email("alice@example.com")
/// .age(30)
/// .build()
/// .unwrap();
/// ```
/// Derive macro `M_Builder` generates a **mutable builder** for a struct,
/// allowing progressive field updates and direct value access.
///
/// Unlike `Builder`, this version uses mutable method calls (`&mut self`)
/// and doesn't consume `self` when calling `.build()`.
///
/// Useful for structs with lifetimes or scenarios where you want to inspect
/// and mutate the builder mid-construction.
///
/// ### Supported field attributes:
///
/// - `#[set(value = "...")]`
/// Sets a default value at construction time (`Struct::new()`).
///
/// - `#[set(skip)]`
/// Skips generating the builder method for this field.
/// Useful for computed or internal fields.
///
/// - `#[range(min = x, max = y, err = "...")]`
/// Adds numeric range validation.
///
/// - `#[build(pattern = "...", err = "...")]`
/// Applies regex validation to string fields.
///
/// - `#[skip_trait]`
/// Prevents automatic implementation of helper traits.
///
/// ### Example:
///
/// ```rust
/// use kenzu::M_Builder;
///
/// #[derive(M_Builder)]
/// pub struct User<'a> {
/// #[set(value = "uuid")]
/// pub id: String,
/// #[set(value = "default")]
/// pub name: String,
/// pub password: String,
/// #[build(pattern = r"^.+@.+\..+$", err = "invalid email")]
/// #[set(value = "email@example.com")]
/// pub email: String,
/// pub fix: &'a str,
/// #[set(value = 18)]
/// pub age: u8,
/// #[set(skip)]
/// pub code: u8,
/// pub def: String,
/// }
///
/// let mut user = User::new();
/// user.id("001")
/// .name("Bob")
/// .password("hunter2")
/// .email("bob@example.com")
/// .fix("static_ref")
/// .age(42)
/// .build()
/// .unwrap();
/// ```