mirror of
https://github.com/nushell/nushell
synced 2025-01-15 22:54:16 +00:00
8386bc0919
# Description Convert these ShellError variants to named fields: * CreateNotPossible * MoveNotPossibleSingle * DirectoryNotFoundCustom * DirectoryNotFound * NotADirectory * OutOfMemoryError * PermissionDeniedError * IOErrorSpanned * IOError * IOInterrupted Also place the `span` field of `DirectoryNotFound` last to match other errors. Part of #10700 (almost half done!) # User-Facing Changes None # Tests + Formatting - 🟢 `toolkit fmt` - 🟢 `toolkit clippy` - 🟢 `toolkit test` - 🟢 `toolkit test stdlib` # After Submitting N/A
36 lines
865 B
Rust
36 lines
865 B
Rust
use crate::ShellError;
|
|
use std::io::{BufRead, BufReader, Read};
|
|
|
|
pub struct BufferedReader<R: Read> {
|
|
pub input: BufReader<R>,
|
|
}
|
|
|
|
impl<R: Read> BufferedReader<R> {
|
|
pub fn new(input: BufReader<R>) -> Self {
|
|
Self { input }
|
|
}
|
|
}
|
|
|
|
impl<R: Read> Iterator for BufferedReader<R> {
|
|
type Item = Result<Vec<u8>, ShellError>;
|
|
|
|
fn next(&mut self) -> Option<Self::Item> {
|
|
let buffer = self.input.fill_buf();
|
|
match buffer {
|
|
Ok(s) => {
|
|
let result = s.to_vec();
|
|
|
|
let buffer_len = s.len();
|
|
|
|
if buffer_len == 0 {
|
|
None
|
|
} else {
|
|
self.input.consume(buffer_len);
|
|
|
|
Some(Ok(result))
|
|
}
|
|
}
|
|
Err(e) => Some(Err(ShellError::IOError { msg: e.to_string() })),
|
|
}
|
|
}
|
|
}
|