From 10c5f796407b082ad4ddab1560b03a36ef72b21d Mon Sep 17 00:00:00 2001 From: Reid Wagner Date: Sun, 10 Feb 2019 20:25:45 -0800 Subject: [PATCH] Revert "Check result of read_until, and return Error if 0, which indicates EOF was found before delimeter." This reverts commit 61e888de7fd1c0a434b532b7e4559b0650f93cbc. --- src/controller.rs | 1 - src/inputfile.rs | 20 +++++++++----------- src/main.rs | 3 --- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/controller.rs b/src/controller.rs index 76323baa..6f38a908 100644 --- a/src/controller.rs +++ b/src/controller.rs @@ -43,7 +43,6 @@ impl<'b> Controller<'b> { for input_file in &self.config.files { match input_file.get_reader(&stdin) { - Err(Error(ErrorKind::ImmediateEOF, _)) => (), Err(error) => { handle_error(&error); no_errors = false; diff --git a/src/inputfile.rs b/src/inputfile.rs index 4b9f060b..eae9c713 100644 --- a/src/inputfile.rs +++ b/src/inputfile.rs @@ -14,11 +14,9 @@ pub struct InputFileReader<'a> { } impl<'a> InputFileReader<'a> { - fn new(mut reader: R) -> Result> { + fn new(mut reader: R) -> InputFileReader<'a> { let mut first_line = vec![]; - if reader.read_until(b'\n', &mut first_line)? == 0 { - return Err(ErrorKind::ImmediateEOF.into()); - } + reader.read_until(b'\n', &mut first_line).ok(); let content_type = content_inspector::inspect(&first_line[..]); @@ -26,11 +24,11 @@ impl<'a> InputFileReader<'a> { reader.read_until(0x00, &mut first_line).ok(); } - Ok(InputFileReader { + InputFileReader { inner: Box::new(reader), first_line, content_type, - }) + } } pub fn read_line(&mut self, buf: &mut Vec) -> io::Result { @@ -59,7 +57,7 @@ pub enum InputFile<'a> { impl<'a> InputFile<'a> { pub fn get_reader(&self, stdin: &'a io::Stdin) -> Result { match self { - InputFile::StdIn => InputFileReader::new(stdin.lock()), + InputFile::StdIn => Ok(InputFileReader::new(stdin.lock())), InputFile::Ordinary(filename) => { let file = File::open(filename).map_err(|e| format!("'{}': {}", filename, e))?; @@ -67,9 +65,9 @@ impl<'a> InputFile<'a> { return Err(format!("'{}' is a directory.", filename).into()); } - InputFileReader::new(BufReader::new(file)) + Ok(InputFileReader::new(BufReader::new(file))) } - InputFile::ThemePreviewFile => InputFileReader::new(THEME_PREVIEW_FILE), + InputFile::ThemePreviewFile => Ok(InputFileReader::new(THEME_PREVIEW_FILE)), } } } @@ -77,7 +75,7 @@ impl<'a> InputFile<'a> { #[test] fn basic() { let content = b"#!/bin/bash\necho hello"; - let mut reader = InputFileReader::new(&content[..]).unwrap(); + let mut reader = InputFileReader::new(&content[..]); assert_eq!(b"#!/bin/bash\n", &reader.first_line[..]); @@ -106,7 +104,7 @@ fn basic() { #[test] fn utf16le() { let content = b"\xFF\xFE\x73\x00\x0A\x00\x64\x00"; - let mut reader = InputFileReader::new(&content[..]).unwrap(); + let mut reader = InputFileReader::new(&content[..]); assert_eq!(b"\xFF\xFE\x73\x00\x0A\x00", &reader.first_line[..]); diff --git a/src/main.rs b/src/main.rs index ed8f2239..5e0d28ce 100644 --- a/src/main.rs +++ b/src/main.rs @@ -63,9 +63,6 @@ mod errors { SyntectError(::syntect::LoadingError); ParseIntError(::std::num::ParseIntError); } - errors { - ImmediateEOF - } } pub fn handle_error(error: &Error) {