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
//! Example demonstrating Former with complex structs containing multiple field types and collections.
//
// Utilizing the Former Crate for Struct Initialization
//
// This example demonstrates the capability of the `Former` crate to simplify struct initialization through the builder pattern, particularly for structs with a mix of required and optional fields, as well as collections like vectors and hash maps.
//
// The `Structure1` struct is defined with various field types to showcase the flexibility of `Former`:
// - `int_1`: A required integer field.
// - `string_1`: A required string field.
// - `vec_1`: A vector of unsigned integers, showcasing collection handling.
// - `hashmap_1`: A hash map storing key-value pairs, both strings, illustrating how `Former` can manage more complex data structures.
// - `int_optional_1`: An optional integer field, demonstrating `Former`'s capability to handle optional fields seamlessly.
// - `string_optional_1`: An optional string field, further exemplifying optional field handling.
//
// A hash map is first created and populated with two key-value pairs. The `Structure1` struct is then instantiated using the fluent builder pattern methods provided by `Former`. Each method corresponds to one of `Structure1`'s fields, allowing for intuitive and clear field assignment. The `.form()` method completes the construction of the `Structure1` instance.
//
// The builder pattern methods significantly streamline the process of struct initialization, especially for structs with complex or optional fields. By leveraging `Former`, developers can write more readable and maintainable initialization code, avoiding the verbosity and complexity often associated with manual struct instantiation.
//
// The `dbg!` macro is utilized to print the constructed `Structure1` instance, confirming that all fields are correctly assigned, including the handling of optional fields and collections.
//#[cfg(not(all(
// feature = "enabled",
// feature = "derive_former",
// any(feature = "use_alloc", not(feature = "no_std"))
//)))]
//fn main() {}
//#[cfg(all(
// feature = "enabled",
// feature = "derive_former",
// any(feature = "use_alloc", not(feature = "no_std"))
//))]