diff --git a/src/main.rs b/src/main.rs index 8338576..448d7cd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -353,19 +353,7 @@ fn main() -> Result<()> { master_log, outfile, } => { - let result = { - let file = File::open(master_log.clone())?; - let reader = BufReader::new(file); - MasterLogResult::parse_file( - reader, - master_log - .file_name() - .unwrap() - .to_str() - .unwrap() - .to_string(), - )? - }; + let result = MasterLogResult::parse_file(master_log)?; debug!("{:?}", result); // Print boards to retest diff --git a/src/masterlog.rs b/src/masterlog.rs index 6db76d8..4957da1 100644 --- a/src/masterlog.rs +++ b/src/masterlog.rs @@ -1,6 +1,7 @@ use std::{ collections::BTreeMap, - io::{BufRead, Write}, + fs::File, + io::{BufRead, BufReader, Write}, path::PathBuf, str::FromStr, }; @@ -107,7 +108,21 @@ fn extract_position_id(line: &str) -> Result<(Position, PsbId)> { impl MasterLogResult { /// Parse log file on master jathub. - pub fn parse_file(file: impl BufRead, filename: String) -> Result { + pub fn parse_file(master_log: PathBuf) -> Result { + let file = File::open(master_log.clone())?; + let reader = BufReader::new(file); + MasterLogResult::parse_file_with_filename( + reader, + master_log + .file_name() + .unwrap() + .to_str() + .unwrap() + .to_string(), + ) + } + + fn parse_file_with_filename(file: impl BufRead, filename: String) -> Result { let mut lines = file.lines(); let version = {