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 31 32 33 34 35 36
use std::io; use std::io::Write; use std::io::Read; use std::fs::File; use std::io::stdout; use std::io::stdin; use std::path::Path; pub type IOResult = Result<String, io::Error>; pub fn prompt(p: &str) -> IOResult { print!("{}", p); let r = stdout().flush(); if r.is_err() { return Err(r.unwrap_err()) } let mut buf = String::new(); stdin().read_line(&mut buf) .map(|_| buf) } pub fn read_file(p: &Path) -> IOResult { let mut file = File::open(p).unwrap(); let mut content = String::new(); file.read_to_string(&mut content) .map(|_| content) } #[cfg(test)] mod tests { #[test] fn it_works() { } }