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
//! This crate was inspired by Python's input function. It allows easy reading of data from the terminal.
//!
//! A simple example of its use is:
//! ```
//! extern crate reader;
//! use reader::input;
//!
//! let name = input("Enter your name: ");
//! println!("Your name is: {}", name);
//! ```
use Write;
use ;
/// Read a String.
///
/// This function works in a similar way to the python "input" function,
/// that receives as an argument a sentence that will be displayed on the screen
/// and returns a String.
///
/// # Examples
///
/// Basic usage
/// ```
/// extern crate reader;
/// use reader::input;
///
/// let name = input("Enter your name: ");
/// println!("Your name is: {}", name);
/// ```
/// Convert a String to integer (i64)
///
/// # Examples
///
/// Basic usage
/// ```
/// extern crate reader;
/// use reader::{input, int};
///
/// Reading a integer (i64)
///
/// let age = int(input("Enter your age: ")).unwrap();
/// println!("Your age is: {}", age);
///
/// Reading a integer (i32)
///
/// let age = int(input("Enter your age: ")).unwrap() as i32;
/// println!("Your age is: {}", age);
///
/// Reading a integer (i16)
///
/// let age = int(input("Enter your age: ")).unwrap() as i16;
/// println!("Your age is: {}", age);
///
/// Reading a integer (i8)
///
/// let age = int(input("Enter your age: ")).unwrap() as i8;
/// println!("Your age is: {}", age);
/// ```
/// Convert a String to float (f64)
///
/// # Examples
///
/// Basic usage
/// ```
/// extern crate reader;
/// use reader::{input, float};
///
/// Reading a float (f64)
///
/// let salary = float(input("Enter your salary: ")).unwrap();
/// println!("Your salary is: {}", salary);
///
/// Reading a float (f32)
///
/// let salary = float(input("Enter your salary: ")).unwrap() as f32;
/// println!("Your salary is: {}", salary);
/// ```