brutils 0.1.51

Some utilities for Rust
Documentation
//! Various utilities for Rust

use std::io;
use std::io::{Write};
use std::cmp::PartialOrd;

pub mod random;
pub mod math;

mod color;
pub use color::Color;

mod thread_pool;
pub use thread_pool::ThreadPool;

/// Clamps given value between min and max
pub fn clamp<T: PartialOrd>(value: T, min: T, max: T) -> T {
    if value < min {
        min
    } else if value > max {
        max
    } else {
        value
    }
}

/// Prints message to console and the retrieves user input as string
pub fn input(msg: &str) -> io::Result<String> {
    print!("{}", msg);
    io::stdout().flush()?;
    let mut buffer = String::new();
    io::stdin().read_line(&mut buffer)?;
    let buffer = buffer.trim().to_owned();
    Ok(buffer)
}