diff --git a/src/main.rs b/src/main.rs index eba76fd..f9c1504 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,13 +32,14 @@ fn main() -> io::Result<()> { }; // Handle output stream (file or stdout) - let output: Box = if let Some(output_path) = matches.get_one::("output") { + let mut output: Box = if let Some(output_path) = matches.get_one::("output") + { Box::new(File::create(output_path)?) } else { Box::new(io::stdout()) }; - BencodeParser::new(input, output).parse()?; + BencodeParser::new(input, &mut output).parse()?; Ok(()) } diff --git a/src/parsers/mod.rs b/src/parsers/mod.rs index f468d2d..751d7cf 100644 --- a/src/parsers/mod.rs +++ b/src/parsers/mod.rs @@ -192,18 +192,13 @@ mod tests { use super::BencodeParser; fn to_json(input_buffer: &[u8]) -> String { - let output_buffer = Vec::new(); + let mut output_buffer = Vec::new(); - let mut parser = BencodeParser::new(input_buffer, output_buffer); + let mut parser = BencodeParser::new(input_buffer, &mut output_buffer); - parser.parse().expect("bencoded to JSON conversion failed"); + parser.parse().expect("Bencode to JSON conversion failed"); - match parser.opt_captured_output() { - Some(captured_output) => captured_output, - None => panic!( - "capturing output is not enabled in parser, please enable it to run the tests" - ), - } + String::from_utf8_lossy(&output_buffer).to_string() } mod integers {