mirror of
https://github.com/mrfluffy-dev/kami.git
synced 2026-01-17 04:50:32 +00:00
37 lines
1002 B
Rust
37 lines
1002 B
Rust
use std::io::{self, Write};
|
|
pub fn string_input(prompt: &str) -> String {
|
|
print!("{}", prompt);
|
|
let mut input = String::new();
|
|
let _ = io::stdout().flush();
|
|
io::stdin()
|
|
.read_line(&mut input)
|
|
.expect("Error reading from STDIN");
|
|
input.trim().to_string()
|
|
}
|
|
|
|
pub fn int_input(prompt: &str) -> usize {
|
|
print!("{}", prompt);
|
|
let mut input = String::new();
|
|
let _ = io::stdout().flush();
|
|
io::stdin()
|
|
.read_line(&mut input)
|
|
.expect("Error reading from STDIN");
|
|
//try to parse the input as usize else return max usize
|
|
match input.trim().parse::<usize>() {
|
|
Ok(i) => i,
|
|
Err(_) => {
|
|
usize::max_value()
|
|
}
|
|
}
|
|
}
|
|
|
|
//pub fn u16_input(prompt: &str) -> u16 {
|
|
// print!("{}", prompt);
|
|
// let mut input = String::new();
|
|
// let _ = io::stdout().flush();
|
|
// io::stdin()
|
|
// .read_line(&mut input)
|
|
// .expect("Error reading from STDIN");
|
|
// input.trim().parse::<u16>().unwrap()
|
|
//}
|