pub struct TextReader<R> { /* private fields */ }
Expand description

A stream reader for large text file

Implementations§

source§

impl TextReader<BufReader<File>>

source

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>>

source

pub fn from_str(s: &'a str) -> Self

Build a text reader for string slice.

source§

impl<R: Read> TextReader<BufReader<R>>

source

pub fn new(r: R) -> Self

Build a text reader from a struct implementing Read trait.

source§

impl<R: BufRead> TextReader<R>

source

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.
source

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.

source

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>

source

pub fn peek_line(&mut self) -> Result<String>

Peek next line without moving cursor.

source

pub fn seek_line<F>(&mut self, f: F) -> Result<usize>
where F: FnMut(&str) -> bool,

Skip reading until finding a matched line. Return the number of bytes read in before the matched line. Return error if not found.

source

pub fn read_until<F>(&mut self, buf: &mut String, f: F) -> Result<usize>
where F: FnMut(&str) -> bool,

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
source

pub fn goto_start(&mut self)

Goto the start of inner file.

source

pub fn goto_end(&mut self)

Goto the end of inner file.

source

pub fn get_current_position(&mut self) -> Result<u64>

Returns the current seek position from the start of the stream.

source

pub fn goto(&mut self, pos: u64) -> Result<()>

Goto to an absolute position, in bytes, in a text stream.

source

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.

Trait Implementations§

source§

impl<R: Debug> Debug for TextReader<R>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<R> RefUnwindSafe for TextReader<R>
where R: RefUnwindSafe,

§

impl<R> Send for TextReader<R>
where R: Send,

§

impl<R> Sync for TextReader<R>
where R: Sync,

§

impl<R> Unpin for TextReader<R>
where R: Unpin,

§

impl<R> UnwindSafe for TextReader<R>
where R: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.