Struct gchemol_parser::TextReader
source · pub struct TextReader<R> { /* private fields */ }
Expand description
A stream reader for large text file
Implementations§
source§impl TextReader<BufReader<File>>
impl TextReader<BufReader<File>>
sourcepub fn try_from_path(p: &Path) -> Result<Self>
pub fn try_from_path(p: &Path) -> Result<Self>
Build a text reader for file from path p
.
source§impl<'a> TextReader<Cursor<&'a str>>
impl<'a> TextReader<Cursor<&'a str>>
source§impl<R: Read> TextReader<BufReader<R>>
impl<R: Read> TextReader<BufReader<R>>
source§impl<R: BufRead> TextReader<R>
impl<R: BufRead> TextReader<R>
sourcepub fn read_line(&mut self, buf: &mut String) -> Result<usize>
pub fn read_line(&mut self, buf: &mut String) -> Result<usize>
Read a new line into buf.
§NOTE
- This function will return the total number of bytes read.
- If this function returns Ok(0), the stream has reached EOF.
sourcepub fn lines(self) -> impl Iterator<Item = String>
pub fn lines(self) -> impl Iterator<Item = String>
Returns an iterator over the lines of this reader. Each string returned will not have a line ending.
sourcepub fn read_to_string(&mut self, buf: &mut String) -> Result<usize>
pub fn read_to_string(&mut self, buf: &mut String) -> Result<usize>
Read all text into string buf
(Note: out of memory issue for large
file)
source§impl<R: BufRead + Seek> TextReader<R>
impl<R: BufRead + Seek> TextReader<R>
sourcepub fn seek_line<F>(&mut self, f: F) -> Result<usize>
pub fn seek_line<F>(&mut self, f: F) -> Result<usize>
Skip reading until finding a matched line. Return the number of bytes read in before the matched line. Return error if not found.
sourcepub fn read_until<F>(&mut self, buf: &mut String, f: F) -> Result<usize>
pub fn read_until<F>(&mut self, buf: &mut String, f: F) -> Result<usize>
Read lines into buf
until f
closure predicates true. Return
total bytes read into buf
.
§NOTE
- the line matching predicate is not included into
buf
sourcepub fn goto_start(&mut self)
pub fn goto_start(&mut self)
Goto the start of inner file.
sourcepub fn get_current_position(&mut self) -> Result<u64>
pub fn get_current_position(&mut self) -> Result<u64>
Returns the current seek position from the start of the stream.
sourcepub fn goto(&mut self, pos: u64) -> Result<()>
pub fn goto(&mut self, pos: u64) -> Result<()>
Goto to an absolute position, in bytes, in a text stream.
sourcepub fn goto_relative(&mut self, offset: i64) -> Result<u64>
pub fn goto_relative(&mut self, offset: i64) -> Result<u64>
Sets the offset to the current position plus the specified number of bytes. If the seek operation completed successfully, this method returns the new position from the start of the stream.