diff options
author | Nora <nora.widdecke@tu-bs.de> | 2019-01-19 00:35:19 +0100 |
---|---|---|
committer | Nora <nora.widdecke@tu-bs.de> | 2019-01-19 02:09:33 +0100 |
commit | eb81302a4539bcf2e10d2cc8dd1e0c25526cf7f2 (patch) | |
tree | c1dac5766dea74ce762fa379ab380918c811733f /src/utils | |
parent | 30edfe9dc7a92b35ba7b308f0eec628346c5c2ba (diff) |
add function read_single_char_from_stdin
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/fileutil.rs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/utils/fileutil.rs b/src/utils/fileutil.rs index 799fbc0..d05cec7 100644 --- a/src/utils/fileutil.rs +++ b/src/utils/fileutil.rs @@ -57,6 +57,12 @@ pub fn read_lines_from_file(filepath: &Path) -> io::Result<impl Iterator<Item = } } +pub fn read_single_char_from_stdin() -> Result<char, String> { + let stdin = std::io::stdin(); + let stdinlock = stdin.lock(); + read_single_char(stdinlock) +} + 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) { @@ -69,7 +75,7 @@ pub fn read_single_char(mut source: impl BufRead) -> Result<char, String> { } } -pub fn read_lines_from_stdin() -> Result<Vec<String>, io::Error> { +pub fn read_lines_from_stdin() -> io::Result<Vec<String>> { let stdin = io::stdin(); let lines = stdin.lock().lines(); |