use std::io::{self, Error as IoError, Read, Result as IoResult, Write};
pub trait ReadExt: Read {
fn read_to_new_string(&mut self) -> IoResult<String> {
let mut s = String::new();
self.read_to_string(&mut s)?;
Ok(s)
}
}
pub fn prompt(message: &str) -> Result<String, IoError> {
{
let out = io::stdout();
let mut lock = out.lock();
write!(lock, "{}", message)?;
lock.flush()?;
}
let mut s = String::new();
io::stdin().read_line(&mut s)?;
Ok(s)
}
#[cfg(test)]
mod tests {
use super::ReadExt;
static_assertions::assert_obj_safe!(ReadExt);
}