[−][src]Struct linereader::LineReader
The LineReader
struct adds buffered, byte-delimited (default: \n
)
reading to any io::Reader.
Methods
impl<R: Read> LineReader<R>
[src]
pub fn new(inner: R) -> Self
[src]
Create a new LineReader
around the reader with a default capacity of
64 KiB and delimiter of \n
.
let reader = LineReader::new(File::open("myfile.txt")?);
pub fn with_capacity(capacity: usize, inner: R) -> Self
[src]
Create a new LineReader
around the reader with a given capacity and
delimiter of \n
.
let mut reader = LineReader::with_capacity(1024*512, File::open("myfile.txt")?);
pub fn with_delimiter(delimiter: u8, inner: R) -> Self
[src]
Create a new LineReader
around the reader with a default capacity of
64 KiB and the given delimiter.
let mut reader = LineReader::with_delimiter(b'\t', File::open("myfile.txt")?);
pub fn with_delimiter_and_capacity(
delimiter: u8,
capacity: usize,
inner: R
) -> Self
[src]
delimiter: u8,
capacity: usize,
inner: R
) -> Self
Create a new LineReader
around the reader with a given capacity and
delimiter.
let mut reader = LineReader::with_delimiter_and_capacity(b'\t', 1024*512, File::open("myfile.txt")?);
pub fn for_each<F: FnMut(&[u8]) -> Result<bool>>(&mut self, f: F) -> Result<()>
[src]
Run the given closure for each line while while the closure returns Ok(true)
.
If either the reader or the closure return an error, iteration ends and the error is returned.
let buf: &[u8] = b"foo\nbar\nbaz"; let mut reader = LineReader::new(buf); let mut lines = vec![]; reader.for_each(|line| { lines.push(line.to_vec()); Ok(true) })?; assert_eq!(lines.len(), 3); assert_eq!(lines[0], b"foo\n"); assert_eq!(lines[1], b"bar\n"); assert_eq!(lines[2], b"baz");
pub fn next_line(&mut self) -> Option<Result<&[u8]>>
[src]
Get the next line from the reader, an IO error, or None
on EOF. The delimiter
is included in any returned slice, unless the file ends without one or a line was
truncated to the buffer size due to length.
while let Some(line) = reader.next_line() { let line = line?; // unwrap io::Result to &[u8] }
pub fn next_batch(&mut self) -> Option<Result<&[u8]>>
[src]
Return a slice of complete lines, up to the size of the internal buffer.
This is functionally identical to next_line, only instead of getting up to the first instance of the delimiter, you get up to the last.
while let Some(lines) = reader.next_batch() { let lines = lines?; // unwrap io::Result to &[u8] }
pub fn reset(&mut self)
[src]
Reset the internal state of the buffer. Next lines are read from wherever the reader happens to be.
pub fn get_ref(&self) -> &R
[src]
Get a reference to the reader.
pub fn get_mut(&mut self) -> &mut R
[src]
Get a mutable reference to the reader.
pub fn into_inner(self) -> R
[src]
Unwrap this LineReader
, returning the underlying reader and discarding any
unread buffered lines.
Trait Implementations
Auto Trait Implementations
impl<R> Send for LineReader<R> where
R: Send,
R: Send,
impl<R> Unpin for LineReader<R> where
R: Unpin,
R: Unpin,
impl<R> Sync for LineReader<R> where
R: Sync,
R: Sync,
impl<R> UnwindSafe for LineReader<R> where
R: UnwindSafe,
R: UnwindSafe,
impl<R> RefUnwindSafe for LineReader<R> where
R: RefUnwindSafe,
R: RefUnwindSafe,
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,