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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412

//! # Introduction
//! Easy Adds is a crate which provides simple rust for beginers and schools
//! Rust is not an easy langage for beginers but with this crate they can do cool things without dificulty
//! 
//! For using this library writte this in the first line of your code
//! ```
//! extern crate easy_adds;
//! use easy_adds::*;
//! ```
//! 
//! # Some usefull functions
//! ```
//! // Generate a random number between 0 and 1
//! random_f64()
//! // NOTE: You can also use random_f32 which return a f32 number instead of a f64 number
//! // You can also generate a number between two numbers with:
//! random(-5,5)
//! // This function returns a i32 between the first and the second number (NOTE: The first number is included but not the second)
//! 
//! // Get an input form the user of the given type ex: input_i64("Type a number: ")
//! input_<Type>("Mesage to sended to the user")
//! // Here all the types supported: f32,f64,bool,i8,i16,i32,i64,u8,u16,u32,u64,string
//! // Note to make a string input: input("Mesage to sended to the user")
//! // You can also use the try_ statement to get an Option<Type> like:
//! try_input_<Type>("Mesage to sended to the user")
//! // This return an option of the given type an this is avaible for all types of the input expect String
//! ```

#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk.png",
       html_favicon_url = "https://www.rust-lang.org/favicon.ico")]



extern crate rand;


use std::io::{stdin};
use rand::prelude::*;

#[cfg(test)]
mod tests {
    #[test]
    fn malou() {
    	assert_eq!("test","test");
        //assert_eq!(crate::input_str("somethings: "), "Malou");
        //assert_eq!(crate::try_input_f64("somethings: ").unwrap(), 32.0);
        //assert_eq!(crate::input_bool("somethings: "), true);
        //assert_eq!(crate::random_f32(), 0.0);
    }
}

/// This function generate random `i32` between `i32` `start` and `end`
/// Based on top of `rand` crate
pub fn random(start: i32,end: i32) -> i32 {
	let mut rng: rand::rngs::ThreadRng = rand::thread_rng();
	rng.gen_range(start,end)
}

/// This function generate random `f64` between 0 and 1.
/// Based on top of `rand` crate.
pub fn random_f64() -> f64 {
	let mut rng: rand::rngs::ThreadRng = rand::thread_rng();
	rng.gen()
}

/// This function generate random `f32` between 0 and 1.
/// Based on top of `rand` crate.
pub fn random_f32() -> f32 {
	let mut rng: rand::rngs::ThreadRng = rand::thread_rng();
	rng.gen()
}

/// This function take a `String` input from the user like `input` and `input_string`
pub fn input_str(message: &str) -> String {
    let mut s=String::new();
    print!("{}",message);
    stdin().read_line(&mut s).expect("Did not enter a correct string");
    if let Some('\n')=s.chars().next_back() {
        s.pop();
    }
    if let Some('\r')=s.chars().next_back() {
        s.pop();
    }
    s
}

/// This function take a `String` input from the user like `input_str` and `input_string`
pub fn input(message: &str) -> String {
    input_str(message)
}

/// This function take a `String` input from the user like `input` and `input_str`
pub fn input_string(message: &str) -> String {
    input_str(message)
}

/// This function take a `f64` input from the user and return an `Option`
pub fn try_input_f64(message: &str) -> Option<f64> {
   match input_str(message).parse::<f64>() {
   		Ok(e) => {
   			Some(e)
   		},
   		_ => {
   			None
   		}
   }
}

/// This function take a `f64` input from the user and return an `f64` but panic if bad input
pub fn input_f64(message: &str) -> f64 {
   match input_str(message).parse::<f64>() {
   		Ok(e) => {
   			e
   		},
   		_ => {
   			panic!("Can't parse user input");
   		}
   }
}

/// This function take a `f32` input from the user and return an `Option`
pub fn try_input_f32(message: &str) -> Option<f32> {
   match input_str(message).parse::<f32>() {
   		Ok(e) => {
   			Some(e)
   		},
   		_ => {
   			None
   		}
   }
}

/// This function take a `f32` input from the user and return an `f32` but panic if bad input
pub fn input_f32(message: &str) -> f32 {
   match input_str(message).parse::<f32>() {
   		Ok(e) => {
   			e
   		},
   		_ => {
   			panic!("Can't parse user input");
   		}
   }
}

/// This function take a `i64` input from the user and return an `Option`
pub fn try_input_i64(message: &str) -> Option<i64> {
   match input_str(message).parse::<i64>() {
   		Ok(e) => {
   			Some(e)
   		},
   		_ => {
   			None
   		}
   }
}

/// This function take a `i64` input from the user and return an `i64` but panic if bad input
pub fn input_i64(message: &str) -> i64 {
   match input_str(message).parse::<i64>() {
   		Ok(e) => {
   			e
   		},
   		_ => {
   			panic!("Can't parse user input");
   		}
   }
}

/// This function take a `i32` input from the user and return an `Option`
pub fn try_input_i32(message: &str) -> Option<i32> {
   match input_str(message).parse::<i32>() {
   		Ok(e) => {
   			Some(e)
   		},
   		_ => {
   			None
   		}
   }
}

/// This function take a `i32` input from the user and return an `i32` but panic if bad input
pub fn input_i32(message: &str) -> i32 {
   match input_str(message).parse::<i32>() {
   		Ok(e) => {
   			e
   		},
   		_ => {
   			panic!("Can't parse user input");
   		}
   }
}

/// This function take a `i16` input from the user and return an `Option`
pub fn try_input_i16(message: &str) -> Option<i16> {
   match input_str(message).parse::<i16>() {
   		Ok(e) => {
   			Some(e)
   		},
   		_ => {
   			None
   		}
   }
}

/// This function take a `i16` input from the user and return an `i16` but panic if bad input
pub fn input_i16(message: &str) -> i16 {
   match input_str(message).parse::<i16>() {
   		Ok(e) => {
   			e
   		},
   		_ => {
   			panic!("Can't parse user input");
   		}
   }
}

/// This function take a `i8` input from the user and return an `Option`
pub fn try_input_i8(message: &str) -> Option<i8> {
   match input_str(message).parse::<i8>() {
   		Ok(e) => {
   			Some(e)
   		},
   		_ => {
   			None
   		}
   }
}

/// This function take a `i8` input from the user and return an `i8` but panic if bad input
pub fn input_i8(message: &str) -> i8 {
   match input_str(message).parse::<i8>() {
   		Ok(e) => {
   			e
   		},
   		_ => {
   			panic!("Can't parse user input");
   		}
   }
}

/// This function take a `u64` input from the user and return an `Option`
pub fn try_input_u64(message: &str) -> Option<u64> {
   match input_str(message).parse::<u64>() {
   		Ok(e) => {
   			Some(e)
   		},
   		_ => {
   			None
   		}
   }
}

/// This function take a `u64` input from the user and return an `u64` but panic if bad input
pub fn input_u64(message: &str) -> u64 {
   match input_str(message).parse::<u64>() {
   		Ok(e) => {
   			e
   		},
   		_ => {
   			panic!("Can't parse user input");
   		}
   }
}

/// This function take a `u32` input from the user and return an `Option`
pub fn try_input_u32(message: &str) -> Option<u32> {
   match input_str(message).parse::<u32>() {
   		Ok(e) => {
   			Some(e)
   		},
   		_ => {
   			None
   		}
   }
}

/// This function take a `u32` input from the user and return an `u32` but panic if bad input
pub fn input_u32(message: &str) -> u32 {
   match input_str(message).parse::<u32>() {
   		Ok(e) => {
   			e
   		},
   		_ => {
   			panic!("Can't parse user input");
   		}
   }
}

/// This function take a `u16` input from the user and return an `Option`
pub fn try_input_u16(message: &str) -> Option<u16> {
   match input_str(message).parse::<u16>() {
   		Ok(e) => {
   			Some(e)
   		},
   		_ => {
   			None
   		}
   }
}

/// This function take a `u16` input from the user and return an `u16` but panic if bad input
pub fn input_u16(message: &str) -> u16 {
   match input_str(message).parse::<u16>() {
   		Ok(e) => {
   			e
   		},
   		_ => {
   			panic!("Can't parse user input");
   		}
   }
}

/// This function take a `u8` input from the user and return an `Option`
pub fn try_input_u8(message: &str) -> Option<u8> {
   match input_str(message).parse::<u8>() {
   		Ok(e) => {
   			Some(e)
   		},
   		_ => {
   			None
   		}
   }
}

/// This function take a `u8` input from the user and return an `u8` but panic if bad input
pub fn input_u8(message: &str) -> u8 {
   match input_str(message).parse::<u8>() {
   		Ok(e) => {
   			e
   		},
   		_ => {
   			panic!("Can't parse user input");
   		}
   }
}


/// This function take a `bool` input from the user and return an `Option`
pub fn try_input_bool(message: &str) -> Option<bool> {
	let de: &str = &(input_str(message).to_lowercase());
   match de {
   		"true" => {
   			Some(true)
   		},
   		"false" => {
   			Some(false)
   		},
   		"t" => {
   			Some(true)
   		},
   		"f" => {
   			Some(false)
   		},
   		"v" => {
   			Some(true)
   		},
   		"o" => {
   			Some(true)
   		},
   		"faux" => {
   			Some(false)
   		},
   		"oui" => {
   			Some(true)
   		},
   		"si" => {
   			Some(true)
   		},
   		"non" => {
   			Some(false)
   		},
   		"vrai" => {
   			Some(true)
   		},
   		"no" => {
   			Some(false)
   		},
   		"yes" => {
   			Some(true)
   		},
   		"0" => {
   			Some(false)
   		},
   		"1" => {
   			Some(true)
   		},
   		_ => {
   			None
   		}
   }
}

/// This function take a `bool` input from the user and return an `bool` return false if there are an bad input
pub fn input_bool(message: &str) -> bool {
   match try_input_bool(message) {
   		Some(e) => {
   			e
   		},
   		_ => {
   			false
   		}
   }
}
/*
pub fn input_string(message: &str) -> String {

}

pub fn input_f64_catch(message: &str) -> Option<f64> {

}*/