use std::path::PathBuf; use std::io::BufReader; use std::io::prelude::*; use std::fs::File; /// Reads a specified file into a vector of strings, one line of the /// file per string. Fails if any part of reading the file fails. pub fn read_file(file: &PathBuf) -> Result, std::io::Error> { let file = File::open(file)?; let file_reader = BufReader::new(file); file_reader.lines() .collect::, _>>() .map(preprocess_file_lines) } /// Removes any empty lines and makes sure that lines don't have /// problematic whitespace. pub fn preprocess_file_lines(lines: Vec) -> Vec { lines.iter() .filter(|line| line.len() > 0) .map(|line| line.trim_right().to_string()) .collect() } #[macro_export] macro_rules! debug { ( $x:expr ) => { println!("{} = {:?}", stringify!($x), $x); }; }