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
pub fn input<'a>(s: impl Into<Option<&'a str>>) -> String {
	let s_into = s.into();
	
	if s_into != None {
		println!("{}", s_into.unwrap());
	}
	
	let mut val = String::new();
	std::io::stdin().read_line(&mut val).expect("Something went wrong with the input.");
	
	return val[0..val.len() - 1].to_string();
}

#[cfg(test)]
mod tests {
    use super::*;
    
    #[test]
    fn input_test() {
        let a = input(None);
        let b = input("Hello there");
        
        assert_eq!(a, "hello");
        assert_eq!(b, "test");
    }
}