Struct IndexedBufReader

Source
pub struct IndexedBufReader<R: Read + Unpin + Seek + Send> {
    pub reader: BufReader<R>,
    /* private fields */
}
Expand description

A wrapper around BufReader<R> which implements ReadByLine and holds an index of the lines.

Fields§

§reader: BufReader<R>

Implementations§

Source§

impl<R: Read + Unpin + Seek + Send> IndexedBufReader<R>

Source

pub fn new(reader: BufReader<R>, index: Arc<Index>) -> IndexedBufReader<R>

Creates a new IndexedBufReader using a BufReader and an index. The index won’t be validated. Using a malformed index won’t return an error but make the IndexedBufReader useless.

Source

pub fn duplicate(&self, reader: BufReader<R>) -> Self

Creates a new IndexedBufReader with the current index. reader should contain the same data used in &self or the index might be invalid for the given reader

Source

pub fn read_all(&mut self, buf: &mut Vec<u8>) -> Result<usize>

Read the IndexedBufReader into a newly allocated string

Trait Implementations§

Source§

impl<R: Debug + Read + Unpin + Seek + Send> Debug for IndexedBufReader<R>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<R: Read + Unpin + Seek + Send> Indexable for IndexedBufReader<R>

Source§

fn get_index(&self) -> &Index

Returns a reference to the files index.
Source§

fn total_lines(&self) -> usize

Returns the total amount of lines in the file without the lines used by the index.
Source§

fn get_index_byte_len(&self) -> usize

Source§

impl<R: Read + Unpin + Seek + Send> IndexableFile for IndexedBufReader<R>

Source§

fn get_offset(&self, line: usize) -> Result<u64>

Should return the offset to seek to given the line-index
Source§

fn read_current_line( &mut self, out_buf: &mut Vec<u8>, line: usize, ) -> Result<usize>

Should read from the current position until the end of the line, omitting the \n
Source§

fn seek_line(&mut self, line: usize) -> Result<()>

Should seek the file to the given line line
Source§

fn write_to<W: Write + Unpin + Send>(&mut self, writer: &mut W) -> Result<usize>

Write the index, followed by the files contents into writer. A file generated using this function will always be parsable by File::open.
Source§

impl<R: Read + Unpin + Seek + Send> ReadByLine for IndexedBufReader<R>

Source§

fn read_line(&mut self, line: usize) -> Result<String>

Reads the given line
Source§

fn read_line_raw(&mut self, line: usize, buf: &mut Vec<u8>) -> Result<usize>

Reads the given line and stores into buf
Do a binary search on ReadByLine implementing Types, since it provides everything required for binary search. Only works with sorted files
Source§

fn binary_search_by<F>(&mut self, f: F) -> Result<usize>
where F: FnMut(&str) -> Ordering,

Do a binary search by on ReadByLine implementing Types, since it provides everything required for binary search. Only works with sorted files
Source§

fn binary_search_raw(&mut self, x: &[u8]) -> Result<usize>

Do a binary search on ReadByLine implementing Types, since it provides everything required for binary search. Only works with sorted files
Source§

fn binary_search_raw_by<F>(&mut self, f: F) -> Result<usize>
where F: FnMut(&[u8]) -> Ordering,

Do a binary search by on ReadByLine implementing Types, since it provides everything required for binary search. Only works with sorted files

Auto Trait Implementations§

§

impl<R> Freeze for IndexedBufReader<R>
where R: Freeze,

§

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

§

impl<R> Send for IndexedBufReader<R>

§

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

§

impl<R> Unpin for IndexedBufReader<R>

§

impl<R> UnwindSafe for IndexedBufReader<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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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.