You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add support for #[builder(into)] attribute (#9)
* feat: add support for #[builder(into)] attribute
* update readme
* update dependencies version
* update typesafe_builder_derive version
* update dependencies version and readme
@@ -119,7 +120,7 @@ let account2 = AccountBuilder::new()
119
120
// .build();
120
121
```
121
122
122
-
### 2️⃣ **Conditional Optional Fields**
123
+
### 2. Conditional Optional Fields
123
124
124
125
```rust
125
126
usetypesafe_builder::*;
@@ -143,7 +144,7 @@ let config2 = ConfigBuilder::new()
143
144
.build();
144
145
```
145
146
146
-
### 3️⃣ **Complex Conditional Logic**
147
+
### 3. Complex Conditional Logic
147
148
148
149
```rust
149
150
usetypesafe_builder::*;
@@ -198,7 +199,7 @@ let client3 = ApiClientBuilder::new()
198
199
.build();
199
200
```
200
201
201
-
### 4️⃣ **Default Values**
202
+
### 4. Default Values
202
203
203
204
```rust
204
205
usetypesafe_builder::*;
@@ -252,14 +253,14 @@ struct AppConfig {
252
253
}
253
254
```
254
255
255
-
**Key features of default values:**
256
-
-**Flexible expressions**: Use any valid Rust expression as default value
257
-
-**No type restrictions**: Works with primitives, collections, function calls, etc.
258
-
-**Environment variables**: Access environment variables at build time
259
-
-**Function calls**: Call any function or method as default value
260
-
-**Standalone attribute**: Cannot be combined with `required`, `optional`, etc.
256
+
Key features of default values:
257
+
- Flexible expressions: Use any valid Rust expression as default value
258
+
- No type restrictions: Works with primitives, collections, function calls, etc.
259
+
- Environment variables: Access environment variables at build time
260
+
- Function calls: Call any function or method as default value
261
+
- Standalone attribute: Cannot be combined with `required`, `optional`, etc.
261
262
262
-
### 5️⃣ **Negation Operator Support**
263
+
### 5. Negation Operator Support
263
264
264
265
```rust
265
266
usetypesafe_builder::*;
@@ -281,7 +282,43 @@ let db = DatabaseBuilder::new()
281
282
.build();
282
283
```
283
284
284
-
### 6️⃣ **Custom Builder Name**
285
+
### 6. Into Conversion Support
286
+
287
+
The `#[builder(into)]` attribute allows setter methods to accept any type that implements `Into<T>` for the field type `T`, providing more ergonomic APIs:
288
+
289
+
```rust
290
+
usetypesafe_builder::*;
291
+
292
+
#[derive(Builder)]
293
+
structUser {
294
+
#[builder(required)]
295
+
#[builder(into)]
296
+
name:String,
297
+
298
+
#[builder(optional)]
299
+
#[builder(into)]
300
+
email:Option<String>,
301
+
}
302
+
303
+
// ✅ Accept &str directly (converts to String via Into)
0 commit comments