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
use std::io;
use std::io::Write;
use std::cmp::PartialOrd;
pub mod random;
pub mod math;
mod color;
pub use color::Color;
pub fn clamp<T: PartialOrd>(value: T, min: T, max: T) -> T {
if value < min {
min
} else if value > max {
max
} else {
value
}
}
pub fn input(msg: &str) -> String {
print!("{}", msg);
io::stdout().flush().expect("Failed to flush the buffer");
let mut buffer = String::new();
io::stdin().read_line(&mut buffer).expect("Failed to read user input");
let buffer = buffer.trim().to_owned();
buffer
}