diff options
author | Nora <nora.widdecke@tu-bs.de> | 2019-01-16 00:43:52 +0100 |
---|---|---|
committer | Nora <nora.widdecke@tu-bs.de> | 2019-01-16 00:43:52 +0100 |
commit | 9a909921b8598efda37bd64da25ee3981c09603d (patch) | |
tree | 00ce04c0fce770d9555e60ffbce6ef2ccaefce95 /src/utils | |
parent | 06f496db77850b61597007ea870e38df1dca1b31 (diff) |
edit: check edited file and allow continued edit
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/fileutil.rs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/utils/fileutil.rs b/src/utils/fileutil.rs index 25051cb..1db5fb8 100644 --- a/src/utils/fileutil.rs +++ b/src/utils/fileutil.rs @@ -46,11 +46,16 @@ pub fn read_lines_from_file(filepath: &Path) -> io::Result<impl Iterator<Item = } } -pub fn read_single_char(mut source: impl Read) -> Result<char, io::Error> { - let mut buffer = [0; 1]; +pub fn read_single_char(mut source: impl BufRead) -> Result<char, String> { + let mut buf = String::new(); + if let Err(error) = source.read_line(&mut buf) { + return Err(format!("{}", error)); + } - source.read(&mut buffer[..])?; - Ok(char::from(buffer[0])) + match buf.chars().next() { + Some(c) => Ok(c), + None => Err("failed to read from stdin".to_string()), + } } pub fn read_lines_from_stdin() -> Result<Vec<String>, io::Error> { |