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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
//! A library for building forms with various fields and validation.
//!
//! This library provides a flexible way to create forms with different types of fields, including text fields, select fields, and multiselect fields. It also supports validation for these fields.
//!
//! # Example
//!
//! ```rust,no_run
//! use form_builder::{FormBuilder, Optional, ValidationMethods, Validator};
//!
//! fn validate_custom(value: &str) -> bool {
//! value.len() > 5
//! }
//!
//! fn main() -> Result<(), String> {
//! let mut form = FormBuilder::new()
//! .add_field::<String>(
//! "name",
//! "Enter name:",
//! Some(Validator::new(vec![
//! (ValidationMethods::not_empty, Some("Name cannot be empty")),
//! (
//! ValidationMethods::validate_name,
//! Some("Name cannot contain numbers"),
//! ),
//! ])),
//! )
//! .add_field::<String>(
//! "email",
//! "Enter email:",
//! Some(Validator::new(vec![
//! (ValidationMethods::not_empty, Some("Email cannot be empty")),
//! (
//! ValidationMethods::validate_email,
//! Some("Invalid email format"),
//! ),
//! ])),
//! )
//! .add_field::<u32>(
//! "age",
//! "Enter age:",
//! Some(Validator::new(vec![(
//! ValidationMethods::not_empty,
//! Some("Age cannot be empty"),
//! )])),
//! )
//! .add_field::<String>(
//! "custom",
//! "Enter custom value:",
//! Some(Validator::new(vec![
//! (
//! ValidationMethods::not_empty,
//! Some("Custom value cannot be empty"),
//! ),
//! (
//! validate_custom,
//! Some("Custom value must be longer than 5 characters"),
//! ),
//! ])),
//! )
//! .add_field::<f64>(
//! "height",
//! "Enter height:",
//! Some(Validator::new(vec![(
//! ValidationMethods::not_empty,
//! Some("Height cannot be empty"),
//! )])),
//! )
//! .add_field::<bool>(
//! "is_student",
//! "Are you a student (true/false):",
//! Some(Validator::new(vec![(
//! ValidationMethods::not_empty,
//! Some("This field cannot be empty"),
//! )])),
//! )
//! .add_field::<char>(
//! "initial",
//! "Enter your initial:",
//! Some(Validator::new(vec![(
//! ValidationMethods::not_empty,
//! Some("Initial cannot be empty"),
//! )])),
//! )
//! .add_field::<Optional<u32>>("width", "Enter width (optional):", None)
//! .add_select(
//! "gender",
//! "Select your gender:",
//! vec![
//! (1u32, "Male"),
//! (2u32, "Female"),
//! (3u32, "Other"),
//! ],
//! )
//! .add_multiselect(
//! "hobbies",
//! "Select your hobbies:",
//! vec![
//! ("reading".to_string(), "Reading"),
//! ("sports".to_string(), "Sports"),
//! ("music".to_string(), "Music"),
//! ],
//! Some(2),
//! )
//! .build();
//!
//! form.fill()?;
//!
//! let name: String = form.get_value("name")?;
//! let email: String = form.get_value("email")?;
//! let age: u32 = form.get_value("age")?;
//! let custom: String = form.get_value("custom")?;
//! let height: f64 = form.get_value("height")?;
//! let is_student: bool = form.get_value("is_student")?;
//! let initial: char = form.get_value("initial")?;
//! let width: Optional<u32> = form.get_value("width")?;
//! let gender: u32 = form.get_value("gender")?;
//! let hobbies: Vec<String> = form.get_value_vec("hobbies")?;
//!
//! let width = process_width(width);
//!
//! println!(
//! "Name: {:?}, Email: {:?}, Age: {:?}, Custom: {:?}, Height: {:?}, Is Student: {:?}, Initial: {:?}, Width: {:?}, Gender: {:?}, Hobbies: {:?}",
//! name, email, age, custom, height, is_student, initial, width, gender, hobbies
//! );
//!
//! Ok(())
//! }
//!
//! fn process_width(width: Optional<u32>) -> u32 {
//! match width {
//! Optional::Some(value) => value + 20,
//! Optional::None => 0,
//! }
//! }
//! ```
/// Module containing definitions for form fields.
/// Module containing definitions for the form.
/// Module containing the form builder.
/// Module containing functions for reading input.
/// Module containing definitions for multiselect fields.
/// Module containing definitions for optional values.
/// Module containing definitions for select fields.
/// Module containing validation methods.
pub use FormBuilder;
pub use Optional;
pub use ;