macon/
lib.rs

1//! Another builder macro-based generator with its own idioms.
2//!
3//! "[Maçon](https://fr.wiktionary.org/wiki/ma%C3%A7on#Nom_commun_2)" is French translation for "[builder](https://www.wordreference.com/enfr/builder)"
4//!
5//! ### Usage
6//!
7//! ```
8//! #[macro_use] extern crate macon;
9//!
10//! #[derive(Builder)]
11//! struct MyType {
12//!   integer: i32,
13//!   string: String,
14//!   optional: Option<String>,
15//! }
16//!
17//! let _mytype: MyType = MyType::builder()
18//!     .integer(42)
19//!     .string("foobar")
20//!     .build();
21//! ```
22//!
23//! * adds a builder struct (`<TargetStruct>Builder`)
24//! * build struct implements [`Default`]
25//! * adds a `builder()` function to target struct to initialize a new builder
26//! * each target struct field can be set with function of same name and parameter of same type
27//! * use `build()` function to create new target struct instance
28//! * any unset field will make `build()` call not compile (default)
29//! * setter argument is generic over [`Into`]
30//! * [`Option`] fields are not mandatory. And setters use wrapped type.
31//!
32//! ### Settings
33//!
34//! Settings are set using `#[builder()]` attribute.
35//!
36//! #### struct
37//!
38//! * **`mode=<value>`** <br/>
39//! Change builder and associated `build()` function behavior. Supported values: [`Typestate`](#typestate-pattern-default) (_default_), [`Panic`](#panic-on-build) or [`Result`](#result-on-build).
40//!
41//! * **`Default=!`** <br/>
42//! Disable automatic [`Default`] derive detection for **struct**. See ["`Default` struct"](#default-struct).
43//!
44//! * **`Default`** <br/>
45//! Enforce [`Default`] support for **struct**. See ["`Default` struct"](#default-struct).
46//!
47//! * **`Option=!`** (_deprecated. Use `fields(Option=!)` instead._)
48//!
49//! * **`Into=!`** (_deprecated. Use `fields(Into=!)` instead._)
50//!
51//! * **`fields(Option=!)`** <br/>
52//! Disable automatic [`Option`] detection for **fields**. See ["`Option` fields"](#option-fields).
53//!
54//! * **`fields(Default=!)`** <br/>
55//! Disable automatic [`Default`] detection for **fields**. See ["`Default` fields"](#default-fields).
56//!
57//! * **`fields(Into=!)`** <br/>
58//! Disable [`Into`] for **fields**. See ["`Into` argument"](#into-argument).
59//!
60//! #### field
61//!
62//! * **`Option=!`** <br/>
63//! Disable automatic [`Option`] detection for given field. Generated setter will rely on declared field type. See ["`Option` fields"](#option-fields).
64//!
65//! * **`Option=WrappedType`** <br/>
66//! Enforce [`Option`] support for given field. Generated setter will rely on `WrappedType`. See ["`Option` fields"](#option-fields).
67//!
68//! * **`Default=!`** <br/>
69//! Disable automatic [`Default`] detection for given field. See ["`Default` fields"](#default-fields).
70//!
71//! * **`Default`** <br/>
72//! Enforce [`Default`] support for given field. See ["`Default` fields"](#default-fields).
73//!
74//! * **`Into=!`** <br/>
75//! Disable [`Into`] for setter. See ["`Into` argument"](#into-argument).
76//!
77//! ### Features
78//!
79//! For any feature, you can find blueprints in [`./tests` directory][tests] showing code generated by macro.
80//!
81//! #### Typestate pattern (default)
82//!
83//! Blueprints:
84//! * [`blueprint_typestate_named.rs`][blueprint_typestate_named.rs]
85//! * [`blueprint_typestate_tuple.rs`][blueprint_typestate_tuple.rs]
86//! * [`blueprint_typestate_option.rs`][blueprint_typestate_option.rs]
87//! * [`blueprint_typestate_default_field.rs`][blueprint_typestate_default_field.rs]
88//! * [`blueprint_typestate_default_struct.rs`][blueprint_typestate_default_struct.rs]
89//!
90//! By default, builder rely on typestate pattern. It means state is encoded in type (using generics). Applicable functions are implemented
91//! (callable) only when state (type) matches:
92//!
93//! * Build function `build()` when all properties has been set
94//! * Each property setter function as long as property haven't been set
95//!
96//! Optionally, you can set it explictly:
97//!
98//! ```
99//! # #[macro_use] extern crate macon;
100//! #[derive(Builder)]
101//! #[builder(mode=Typestate)]
102//! struct MyType {
103//!   integer: i32,
104//!   string: String,
105//! }
106//!
107//! // Builder signature
108//! # struct Builder;
109//! impl Builder {
110//!   fn integer(self, value: i32) -> Self
111//! # { unimplemented!(); }
112//!   fn string(self, value: String) -> Self
113//! # { unimplemented!(); }
114//!   fn build(self) -> MyType
115//! # { unimplemented!();  }
116//! }
117//! ```
118//!
119//! #### Panic on `build()`
120//!
121//! Blueprints:
122//! * [`blueprint_panic_named.rs`][blueprint_panic_named.rs]
123//! * [`blueprint_panic_tuple.rs`][blueprint_panic_tuple.rs]
124//! * [`blueprint_panic_option.rs`][blueprint_panic_option.rs]
125//! * [`blueprint_panic_default_field.rs`][blueprint_panic_default_field.rs]
126//! * [`blueprint_panic_default_struct.rs`][blueprint_panic_default_struct.rs]
127//!
128//! By default, builder rely on typestate pattern to avoid misconfiguration by adding compilation constraint. You can switch to a builder
129//! that just panic when misconfigured:
130//!
131//! ```should_panic
132//! # #[macro_use] extern crate macon;
133//! # use std::path::PathBuf;
134//! #[derive(Builder)]
135//! #[builder(mode=Panic)]
136//! struct MyType {
137//!   integer: i32,
138//!   path: PathBuf,
139//! }
140//!
141//! // Builder signature
142//! # struct Builder;
143//! impl Builder {
144//!   fn integer(self, value: i32) -> Self
145//! # { unimplemented!(); }
146//!   fn path(self, value: PathBuf) -> Self
147//! # { unimplemented!(); }
148//!   fn build(self) -> MyType
149//! # { unimplemented!(); }
150//! }
151//!
152//! let _mytype: MyType = MyType::builder()
153//!     .integer(42)
154//!     .build();
155//! ```
156//!
157//! #### Result on `build()`
158//!
159//! Blueprints:
160//! * [`blueprint_result_named.rs`][blueprint_result_named.rs]
161//! * [`blueprint_result_tuple.rs`][blueprint_result_tuple.rs]
162//! * [`blueprint_result_option.rs`][blueprint_result_option.rs]
163//! * [`blueprint_result_default_field.rs`][blueprint_result_default_field.rs]
164//! * [`blueprint_result_default_struct.rs`][blueprint_result_default_struct.rs]
165//!
166//! By default, builder rely on typestate pattern to avoid misconfiguration by adding compilation constraint. You can switch to a builder
167//! that returns a [`Result`]:
168//!
169//! ```
170//! # #[macro_use] extern crate macon;
171//! # use std::path::PathBuf;
172//! #[derive(Builder)]
173//! #[builder(mode=Result)]
174//! struct MyType {
175//!   integer: i32,
176//!   path: PathBuf,
177//! }
178//!
179//! // Builder signature
180//! # struct Builder;
181//! impl Builder {
182//!   fn integer(self, value: i32) -> Self
183//! # { unimplemented!(); }
184//!   fn path(self, value: PathBuf) -> Self
185//! # { unimplemented!(); }
186//!   fn build(self) -> Result<MyType, String>
187//! # { unimplemented!(); }
188//! }
189//!
190//! let myTypeResult: Result<MyType,String> = MyType::builder()
191//!     .integer(42)
192//!     .build();
193//!
194//! assert_eq!(
195//!     Err(String::from("Field path is missing")),
196//!     myTypeResult.map(|_| ())
197//! );
198//! ```
199//!
200//! #### Tuple
201//!
202//! Blueprints:
203//! * [`blueprint_typestate_tuple.rs`][blueprint_typestate_tuple.rs]
204//! * [`blueprint_panic_tuple.rs`][blueprint_panic_tuple.rs]
205//! * [`blueprint_result_tuple.rs`][blueprint_result_tuple.rs]
206//!
207//! A tuple is a struct with unamed fields. Then `set<ordinal>()` is used as setter:
208//!
209//! ```
210//! # #[macro_use] extern crate macon;
211//! #[derive(Builder)]
212//! struct MyTuple(
213//!   i32,
214//!   Option<String>,
215//!   String,
216//! );
217//!
218//! // Builder signature
219//! # struct Builder;
220//! impl Builder {
221//!   fn set0(self, value: i32) -> Self
222//! # { unimplemented!(); }
223//!   fn set1(self, value: String) -> Self
224//! # { unimplemented!(); }
225//!   fn set2(self, value: String) -> Self
226//! # { unimplemented!(); }
227//!   fn build(self) -> MyTuple
228//! # { unimplemented!(); }
229//! }
230//!
231//! let _mytuple: MyTuple = MyTuple::builder()
232//!     .set0(42)
233//!     .set2(String::from("foobar"))
234//!     .build();
235//! ```
236//!
237//! Only for [`Typestate` mode](#typestate-pattern-default), you can chain `set()`, [`none()`](#option-fields), [`keep()`](#default-struct) and [`default()`](#default-fields) calls to assign values in order:
238//!
239//! ```
240//! # #[macro_use] extern crate macon;
241//! # #[derive(Builder)]
242//! # struct MyTuple(
243//! #   i32,
244//! #   Option<String>,
245//! #   String,
246//! # );
247//!
248//! // Builder signature
249//! # struct Builder0;
250//! impl Builder0 {
251//!   fn set(self, value: i32) -> Builder1
252//! # { unimplemented!(); }
253//! }
254//! # struct Builder1;
255//! impl Builder1 {
256//!   fn set(self, value: String) -> Builder2
257//! # { unimplemented!(); }
258//!   fn none(self) -> Builder2
259//! # { unimplemented!(); }
260//! }
261//! # struct Builder2;
262//! impl Builder2 {
263//!   fn set(self, value: String) -> Builder
264//! # { unimplemented!(); }
265//! }
266//! # struct Builder;
267//! impl Builder {
268//!   fn build(self) -> MyTuple
269//! # { unimplemented!(); }
270//! }
271//!
272//! let _mytuple: MyTuple = MyTuple::builder()
273//!     .set(42)
274//!     .none()
275//!     .set(String::from("foobar"))
276//!     .build();
277//! ```
278//!
279//! #### `Into` argument
280//!
281//! Blueprints:
282//! * [`blueprint_typestate_named.rs`][blueprint_typestate_named.rs]
283//! * [`blueprint_panic_named.rs`][blueprint_panic_named.rs]
284//! * [`blueprint_result_named.rs`][blueprint_result_named.rs]
285//!
286//! Setter function argument is generic over [`Into`] to ease conversion (especially for `&str`):
287//!
288//! ```
289//! # #[macro_use] extern crate macon;
290//! #[derive(Builder)]
291//! struct MyTuple(
292//!   String,
293//! );
294//!
295//! // Builder signature
296//! # struct Builder0;
297//! # struct Builder;
298//! impl Builder0 {
299//!   fn set<V: Into<String>>(self, value: V) -> Builder
300//! # { unimplemented!(); }
301//! }
302//! impl Builder {
303//!   fn build(self) -> MyTuple
304//! # { unimplemented!(); }
305//! }
306//!
307//! let _mytuple: MyTuple = MyTuple::builder()
308//!     .set("foobar")
309//!     .build();
310//! ```
311//!
312//! You can disable [`Into`] support by using `#[builder(Into=!)]` at struct or field level:
313//!
314//! ```
315//! # #[macro_use] extern crate macon;
316//! #[derive(Builder)]
317//! #[builder(Into=!)]     // Disable for all fields
318//! struct IntoSettings {
319//!   #[builder(Into=!)]   // Disable for specific field
320//!   no_into: String,
321//!   #[builder(Into)]     // Enable (only when disabled at struct level) for specific field
322//!   with_into: String,
323//! }
324//!
325//! // Builder signature
326//! # struct Builder;
327//! impl Builder {
328//!   fn no_into(value: String) -> Self
329//! # { unimplemented!(); }
330//!   fn with_into<V: Into<String>>(value: V) -> Self
331//! # { unimplemented!(); }
332//!   fn build(self) -> IntoSettings
333//! # { unimplemented!(); }
334//! }
335//!
336//! let built = IntoSettings::builder()
337//!   .no_into(String::from("no value conversion"))
338//!   .with_into("value conversion")
339//!   .build();
340//!
341//! assert_eq!(String::from("no value conversion"), built.no_into);
342//! assert_eq!(String::from("value conversion"), built.with_into);
343//! ```
344//!
345//! This feature is required to use with [`dyn` trait](https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait):
346//!
347//! ```
348//! # #[macro_use] extern crate macon;
349//! #[derive(Builder)]
350//! struct DynTrait {
351//!   #[builder(Into=!)]
352//!   function: Box<dyn Fn(usize) -> usize>,
353//! }
354//!
355//! // Builder signature
356//! # struct Builder;
357//! impl Builder {
358//!   fn function(self, value: Box<dyn Fn(usize) -> usize>) -> Self
359//! # { unimplemented!(); }
360//!   fn build(self) -> DynTrait
361//! # { unimplemented!(); }
362//! }
363//!
364//! DynTrait::builder()
365//!   .function(Box::new(|x| x + 1))
366//!   .build();
367//! ```
368//!
369//! #### Implement `Into`
370//!
371//! Blueprints:
372//! * [`blueprint_typestate_named.rs`][blueprint_typestate_named.rs]
373//! * [`blueprint_panic_named.rs`][blueprint_panic_named.rs]
374//! * [`blueprint_result_named.rs`][blueprint_result_named.rs]
375//!
376//! Builders implement [`Into`] for target type (and reverse [`From`] also). Except for `Result` mode which uses [`TryInto`] / [`TryFrom`].
377//!
378//! ```
379//! # #[macro_use] extern crate macon;
380//! # #[derive(Builder)]
381//! # struct MyStruct {
382//! #   value: String,
383//! # };
384//! let _mytuple: MyStruct = MyStruct::builder()
385//!     .value("foobar")
386//!     .into();
387//! ```
388//!
389//! #### `Option` fields
390//!
391//! Blueprints:
392//! * [`blueprint_typestate_option.rs`][blueprint_typestate_option.rs]
393//! * [`blueprint_panic_option.rs`][blueprint_panic_option.rs]
394//! * [`blueprint_result_option.rs`][blueprint_result_option.rs]
395//!
396//! As their name suggests, [`Option`] fields are facultative: you can build instance without setting them explicitly.
397//!
398//! Setter argument are still generic over [`Into`] but for wrapped type. No need to wrap into an [`Option`]:
399//!
400//! ```
401//! # #[macro_use] extern crate macon;
402//! #[derive(Builder)]
403//! struct WithOptional {
404//!   mandatory: String,
405//!   discretionary: Option<String>,
406//! }
407//!
408//! // Builder signature
409//! # struct Builder;
410//! impl Builder {
411//!   fn mandatory(self, value: String) -> Self
412//! # { unimplemented!(); }
413//!   fn discretionary(self, value: String) -> Self
414//! # { unimplemented!(); }
415//!   fn build(self) -> WithOptional
416//! # { unimplemented!(); }
417//! }
418//!
419//! let built = WithOptional::builder()
420//!   .discretionary("optional value")
421//!   .mandatory("some value")
422//!   .build();
423//!
424//! assert_eq!(Some(String::from("optional value")), built.discretionary);
425//! ```
426//!
427//! You can set them explicitly to [`None`](https://doc.rust-lang.org/core/option/enum.Option.html#variant.None) with `<field>_none()` or `none()` for ordered setter:
428//!
429//! ```
430//! # #[macro_use] extern crate macon;
431//! #[derive(Builder)]
432//! pub struct WithOptional {
433//!   mandatory: String,
434//!   discretionary: Option<String>,
435//! }
436//!
437//! // Builder signature
438//! # struct Builder;
439//! impl Builder {
440//!   fn mandatory<V: Into<String>>(self, value: V) -> Self
441//! # { unimplemented!(); }
442//!   fn discretionary_none(self) -> Self
443//! # { unimplemented!(); }
444//!   fn build(self) -> WithOptional
445//! # { unimplemented!(); }
446//! }
447//!
448//! let built = WithOptional::builder()
449//!   .discretionary_none()
450//!   .mandatory("some value")
451//!   .build();
452//!
453//! assert_eq!(None, built.discretionary);
454//! ```
455//!
456//! <div class="warning">
457//!
458//! Note: In order to detect optional fields, field type **name** must match:
459//!
460//! * `core::option::Option`
461//! * `::core::option::Option`
462//! * `std::option::Option`
463//! * `::std::option::Option`
464//! * `Option`
465//!
466//! </div>
467//!
468//! You can disable [`Option`] support by using `#[builder(Option=!)]` at struct or field level:
469//!
470//! ```
471//! # #[macro_use] extern crate macon;
472//! #[derive(Builder)]
473//! #[builder(Option=!)]
474//! struct DisableOptionStruct {
475//!   discretionary: Option<String>,
476//! }
477//!
478//! // Builder signature
479//! # struct Builder;
480//! impl Builder {
481//!   fn discretionary(self, value: Option<String>) -> Self
482//! # { unimplemented!(); }
483//!   fn build(self) -> DisableOptionStruct
484//! # { unimplemented!(); }
485//! }
486//!
487//! let built = DisableOptionStruct::builder()
488//!   .discretionary(Some(String::from("mandatory value")))
489//!   .build();
490//!
491//! assert_eq!(Some(String::from("mandatory value")), built.discretionary);
492//! ```
493//!
494//! If you use an alias, use `#[builder(Option=<WrappedType>)]` at field level to enable [`Option`] support:
495//!
496//! ```
497//! # #[macro_use] extern crate macon;
498//! type OptString = Option<String>;
499//! #[derive(Builder)]
500//! struct AliasedOptionStruct {
501//!   #[builder(Option=String)]
502//!   discretionary: OptString,
503//! }
504//!
505//! // Builder signature
506//! # struct Builder;
507//! impl Builder {
508//!   fn discretionary(self, value: String) -> Self
509//! # { unimplemented!(); }
510//!   fn build(self) -> AliasedOptionStruct
511//! # { unimplemented!(); }
512//! }
513//!
514//! let built = AliasedOptionStruct::builder()
515//!   .discretionary("aliased value")
516//!   .build();
517//!
518//! assert_eq!(Some(String::from("aliased value")), built.discretionary);
519//! ```
520//!
521//! If you are already dealing with [`Option`], use `<field>_optional` or `optional` for ordered setter:
522//!
523//! ```
524//! # #[macro_use] extern crate macon;
525//! #[derive(Builder)]
526//! struct WithOptional {
527//!   discretionary: Option<String>,
528//! }
529//!
530//! // Builder signature
531//! # struct Builder;
532//! impl Builder {
533//!   fn discretionary_optional(self, value: Option<String>) -> Self
534//! # { unimplemented!(); }
535//!   fn build(self) -> Self
536//! # { unimplemented!(); }
537//! }
538//!
539//! let discretionary = Some("any");
540//! let built = WithOptional::builder()
541//!   .discretionary_optional(discretionary)
542//!   .build();
543//!
544//! assert_eq!(Some(String::from("any")), built.discretionary);
545//! ```
546//!
547//! #### `Default` struct
548//!
549//! Blueprints:
550//! * [`blueprint_typestate_default_struct.rs`][blueprint_typestate_default_struct.rs]
551//! * [`blueprint_panic_default_struct.rs`][blueprint_panic_default_struct.rs]
552//! * [`blueprint_result_default_struct.rs`][blueprint_result_default_struct.rs]
553//!
554//! If struct derives [`Default`], all fields are then optional and values are kept from default instance:
555//!
556//! <div class="warning">
557//!
558//! Note: In order to detect [`Default`] derive, `Builder` derive attribute must be placed before other derive attributes.
559//!
560//! </div>
561//!
562//! ```
563//! # #[macro_use] extern crate macon;
564//! #[derive(Builder,)]
565//! #[derive(Default,PartialEq,Debug,)]
566//! struct DeriveDefaultStruct {
567//!   integer: usize,
568//!   string: String,
569//!   optional: Option<String>,
570//! }
571//!
572//! let built = DeriveDefaultStruct::builder()
573//!   .build();
574//!
575//! assert_eq!(
576//!   DeriveDefaultStruct {
577//!     integer: 0,
578//!     string: String::from(""),
579//!     optional: None,
580//!   },
581//!   built,
582//! );
583//! ```
584//!
585//! In case [`Default`] derive detection is undesired, you can disable it with `#[builder(Default=!)]`.
586//!
587//! On the other hand, if have your own [`Default`] implementation, you can add `#[builder(Default)]` to enable support.
588//!
589//! ```
590//! # #[macro_use] extern crate macon;
591//! #[derive(Builder,)]
592//! #[derive(PartialEq,Debug,)]
593//! #[builder(Default,)]
594//! struct CustomDefaultStruct {
595//!   integer: usize,
596//!   string: String,
597//!   optional: Option<String>,
598//! }
599//!
600//! impl Default for CustomDefaultStruct {
601//!     fn default() -> Self {
602//!         CustomDefaultStruct {
603//!             integer: 42,
604//!             string: String::from("plop!"),
605//!             optional: Some(String::from("some")),
606//!         }
607//!     }
608//! }
609//!
610//! let built = CustomDefaultStruct::builder()
611//!   .build();
612//!
613//! assert_eq!(
614//!   CustomDefaultStruct {
615//!     integer: 42,
616//!     string: String::from("plop!"),
617//!     optional: Some(String::from("some")),
618//!   },
619//!   built,
620//! );
621//! ```
622//!
623//! You can keep default value (from default built instance) explicitly with `<field>_keep()` or `keep()` for ordered setter:
624//!
625//! ```
626//! # #[macro_use] extern crate macon;
627//! # #[derive(Builder,)]
628//! # #[derive(PartialEq,Debug,)]
629//! # #[builder(Default,)]
630//! # struct CustomDefaultStruct {
631//! #  integer: usize,
632//! #  string: String,
633//! #  optional: Option<String>,
634//! # }
635//! #
636//! # impl Default for CustomDefaultStruct {
637//! #     fn default() -> Self {
638//! #         CustomDefaultStruct {
639//! #             integer: 42,
640//! #             string: String::from("plop!"),
641//! #             optional: Some(String::from("some")),
642//! #         }
643//! #     }
644//! # }
645//!
646//! // Builder signature
647//! # struct Builder;
648//! impl Builder {
649//!   fn integer<V: Into<usize>>(self, value: V) -> Self
650//! # { unimplemented!(); }
651//!   fn integer_keep(self) -> Self
652//! # { unimplemented!(); }
653//!   fn string<V: Into<String>>(self, value: V) -> Self
654//! # { unimplemented!(); }
655//!   fn string_keep(self) -> Self
656//! # { unimplemented!(); }
657//!   fn optional<V: Into<String>>(self, value: V) -> Self
658//! # { unimplemented!(); }
659//!   fn optional_none(self) -> Self
660//! # { unimplemented!(); }
661//!   fn optional_keep(self) -> Self
662//! # { unimplemented!(); }
663//!   fn build(self) -> CustomDefaultStruct
664//! # { unimplemented!(); }
665//! }
666//!
667//! let built = CustomDefaultStruct::builder()
668//!   .integer_keep()
669//!   .string("overriden")
670//!   .optional_none()
671//!   .build();
672//!
673//! assert_eq!(
674//!   CustomDefaultStruct {
675//!     integer: 42,
676//!     string: String::from("overriden"),
677//!     optional: None,
678//!   },
679//!   built,
680//! );
681//! ```
682//!
683//! #### `Default` fields
684//!
685//! Blueprints:
686//! * [`blueprint_typestate_default_field.rs`][blueprint_typestate_default_field.rs]
687//! * [`blueprint_panic_default_field.rs`][blueprint_panic_default_field.rs]
688//! * [`blueprint_result_default_field.rs`][blueprint_result_default_field.rs]
689//!
690//! If field implements [`Default`], it is then optional and value is:
691//!
692//! 1. kept from default instance if [struct derives `Default`](#default-struct),
693//! 1. or, initialized with default value.
694//!
695//! ```
696//! # #[macro_use] extern crate macon;
697//! #[derive(Builder)]
698//! #[derive(Debug,PartialEq,)]
699//! struct WithDefaultFields {
700//!   integer: usize,
701//!   string: String,
702//!   optional: Option<String>,
703//! }
704//!
705//! // Builder signature
706//! # struct Builder;
707//! impl Builder {
708//!   fn integer<V: Into<usize>>(self, value: V) -> Self
709//! # { unimplemented!(); }
710//!   fn integer_default(self) -> Self
711//! # { unimplemented!(); }
712//!   fn string<V: Into<String>>(self, value: V) -> Self
713//! # { unimplemented!(); }
714//!   fn build(self) -> WithDefaultFields
715//! # { unimplemented!(); }
716//! }
717//!
718//! let built = WithDefaultFields::builder()
719//!   .build();
720//!
721//! assert_eq!(
722//!   WithDefaultFields {
723//!     integer: 0,
724//!     string: String::from(""),
725//!     optional: None,
726//!   },
727//!   built,
728//! );
729//! ```
730//!
731//! You can set them explicitly to default with `<field>_default()` or `default()` for ordered setter (e.g. [override default instance value](#default-struct)):
732//!
733//! ```
734//! # #[macro_use] extern crate macon;
735//! # #[derive(Builder)]
736//! # #[derive(Debug,PartialEq,)]
737//! # struct WithDefaultFields {
738//! #   integer: usize,
739//! #   string: String,
740//! #   optional: Option<String>,
741//! # }
742//! #
743//! let built = WithDefaultFields::builder()
744//!   .integer_default()
745//!   .string_default()
746//!   .optional_default()
747//!   .build();
748//!
749//! assert_eq!(
750//!   WithDefaultFields {
751//!     integer: 0,
752//!     string: String::from(""),
753//!     optional: None,
754//!   },
755//!   built,
756//! );
757//! ```
758//!
759//! <div class="warning">
760//!
761//! In order to detect default fields, field type **name** must match (leading `::` and module path are optionals):
762//!
763//! * `bool`
764//! * `char`
765//! * `f32`
766//! * `f64`
767//! * `i8`
768//! * `i16`
769//! * `i32`
770//! * `i64`
771//! * `i128`
772//! * `isize`
773//! * `str`
774//! * `u8`
775//! * `u16`
776//! * `u32`
777//! * `u64`
778//! * `u128`
779//! * `usize`
780//! * `std::string::String`
781//! * `core::option::Option`
782//! * `std::option::Option`
783//! * `std::vec::Vec`
784//! * `alloc::vec::Vec`
785//! * `std::collections::HashMap`
786//! * `std::collections::hash_map::HashMap`
787//! * `std::collections::HashSet`
788//! * `std::collections::hash_set::HashSet`
789//!
790//! </div>
791//!
792//! If you use an alias or unsupported type, use `#[builder(Default)]` at field level to enable [`Default`] support:
793//!
794//! ```
795//! # #[macro_use] extern crate macon;
796//! #[derive(Builder)]
797//! #[derive(Debug,PartialEq,)]
798//! struct ExplicitDefaultOnField {
799//!   #[builder(Default)]
800//!   boxed: Box<usize>,
801//! }
802//!
803//! // Builder signature
804//! # struct Builder;
805//! impl Builder {
806//!   fn boxed<V: Into<Box<usize>>>(self, value: V) -> Self
807//! # { unimplemented!(); }
808//!   fn boxed_default(self) -> Self
809//! # { unimplemented!(); }
810//!   fn build(self) -> ExplicitDefaultOnField
811//! # { unimplemented!(); }
812//! }
813//!
814//! let built = ExplicitDefaultOnField::builder()
815//!     .build();
816//!
817//! assert_eq!(
818//!   ExplicitDefaultOnField {
819//!     boxed: Box::from(0),
820//!   },
821//!   built,
822//! );
823//! ```
824//!
825//! You can disable [`Default`] support by using `#[builder(Default=!)]` at field level:
826//!
827//! ```compile_fail
828//! # #[macro_use] extern crate macon;
829//! #[derive(Builder)]
830//! struct DisableDefaultOnField {
831//!   #[builder(Default=!)]
832//!   integer: usize,
833//! }
834//!
835//! DisableDefaultOnField::builder()
836//!   .integer_default()
837//!   .build();
838//! ```
839//!
840//!
841//! [tests]: https://github.com/loganmzz/macon-rs/tree/1.3.0/tests
842//! [blueprint_panic_default_field.rs]: https://github.com/loganmzz/macon-rs/blob/1.3.0/tests/blueprint_panic_default_field.rs
843//! [blueprint_panic_default_struct.rs]: https://github.com/loganmzz/macon-rs/blob/1.3.0/tests/blueprint_panic_default_struct.rs
844//! [blueprint_panic_named.rs]: https://github.com/loganmzz/macon-rs/blob/1.3.0/tests/blueprint_panic_named.rs
845//! [blueprint_panic_option.rs]: https://github.com/loganmzz/macon-rs/blob/1.3.0/tests/blueprint_panic_option.rs
846//! [blueprint_panic_tuple.rs]: https://github.com/loganmzz/macon-rs/blob/1.3.0/tests/blueprint_panic_tuple.rs
847//! [blueprint_result_default_field.rs]: https://github.com/loganmzz/macon-rs/blob/1.3.0/tests/blueprint_result_default_field.rs
848//! [blueprint_result_default_struct.rs]: https://github.com/loganmzz/macon-rs/blob/1.3.0/tests/blueprint_result_default_struct.rs
849//! [blueprint_result_named.rs]: https://github.com/loganmzz/macon-rs/blob/1.3.0/tests/blueprint_result_named.rs
850//! [blueprint_result_option.rs]: https://github.com/loganmzz/macon-rs/blob/1.3.0/tests/blueprint_result_option.rs
851//! [blueprint_result_tuple.rs]: https://github.com/loganmzz/macon-rs/blob/1.3.0/tests/blueprint_result_tuple.rs
852//! [blueprint_typestate_default_field.rs]: https://github.com/loganmzz/macon-rs/blob/1.3.0/tests/blueprint_typestate_default_field.rs
853//! [blueprint_typestate_default_struct.rs]: https://github.com/loganmzz/macon-rs/blob/1.3.0/tests/blueprint_typestate_default_struct.rs
854//! [blueprint_typestate_named.rs]: https://github.com/loganmzz/macon-rs/blob/1.3.0/tests/blueprint_typestate_named.rs
855//! [blueprint_typestate_option.rs]: https://github.com/loganmzz/macon-rs/blob/1.3.0/tests/blueprint_typestate_option.rs
856//! [blueprint_typestate_tuple.rs]: https://github.com/loganmzz/macon-rs/blob/1.3.0/tests/blueprint_typestate_tuple.rs
857//!
858
859pub use ::macon_derive::*;
860pub use ::macon_api::*;