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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
//! Prompts the user for input and parses the input as a value of type 'T'.
//!
//! If the input cannot be parsed as the request 'T', the function will prompt the user again
//! until a valid input is entered.
//!
//! # Arguments
//!
//! * 'prompt' - A string that will be printed to the console to prompt the user for input.
//!
//! # Returns
//!
//! A value of type 'T' that was parsed from the user's input.
//!
//! # Panics
//! This function will panic if 'T' does not implement the 'FromStr' trait.
use ;
use Regex;
/// Returns the decimal separator
/// Prompts the user for input and parses the user's response as a specified type.
///
/// This function repeatedly prompts the user for input until the user provides input that can be
/// successfully parsed as the specified type `T`. If the user's input cannot be parsed as `T`,
/// the function will continue to prompt the user for input.
///
/// # Examples
///
/// ```
/// use input_validation::get_input;
///
/// let name: String = get_input("What is your name? ");
/// println!("Hello, {}!", name);
/// ```
///
/// ```
/// use input_validation::get_input;
///
/// let age: u32 = get_input("How old are you? ");
/// println!("You are {} years old.", age);
/// ```
///
/// # Panics
///
/// This function will panic if it is unable to write to the standard output stream.
///
/// # Errors
///
/// This function will return an error if it is unable to read from the standard input stream or
/// if the user's input cannot be parsed as the specified type `T`.
/// Reads input from the user and returns a vector of elements of type T.
///
/// This function prompts the user for input using the specified `prompt` and then splits
/// the input string into individual elements using the specified `separator`. If all of the
/// elements can be parsed into type `T`, then they are returned as a `Vec<T>`. If any of the
/// elements fail to parse, the function will loop and prompt the user for input again.
///
/// # Examples
///
/// ```rust
/// let numbers: Vec<i32> = get_list("Enter some numbers, separated by commas: ", ",");
/// ```
///
/// # Panics
///
/// This function will panic if `separator` is an empty string.
///
/// # Errors
///
/// This function will keep looping and prompting for input if any of the elements fail to parse
/// into type `T`. The error message from the parsing failure is printed to stderr.
///
/// Prompts the user for a boolean input, returning `true` if the input is
/// "y" or "yes" (case insensitive), and `false` if the input is "n" or "no"
/// (case insensitive). If the input does not match either "y", "yes", "n", or
/// "no", the function will loop and prompt the user again.
///
/// # Arguments
///
/// * `prompt` - A string slice that will be displayed to the user as the prompt
/// for their input.
///
/// # Example
///
/// ```
/// use user_input::{get_bool};
///
/// let confirm = get_bool("Are you sure you want to proceed? (y/n) ");
/// if confirm {
/// println!("User confirmed.");
/// } else {
/// println!("User declined.");
/// }
/// ```
/// Prompts the user to select a choice from a list of options and returns the index of the selected choice.
///
/// # Arguments
///
/// * `prompt` - A string slice containing the prompt to display to the user.
/// * `choices` - A slice containing the available choices.
///
/// # Examples
///
/// ```
/// let choices = vec!["Option 1", "Option 2", "Option 3"];
/// let index = get_choice("Please select an option", &choices);
/// println!("You selected: {}", choices[index]);
/// ```
/// Prompts the user to enter an email address and returns it as a string.
///
/// The function ensures that the email address is valid and has the correct format.
///
/// # Examples
///
/// ```
/// use rust_input_lib::get_email;
///
/// let email = get_email("Enter your email address: ");
/// println!("Your email address is: {}", email);
/// ```