Struct File

Source
pub struct File(/* private fields */);
Expand description

A wrapper around std::fs::File which implements ReadByLine and holds an index of the lines.

Implementations§

Source§

impl File

Source

pub fn open<P: AsRef<Path>>(path: P) -> Result<File>

Open a new indexed file.

Returns an error if the index is malformed, missing or an io error occurs

Source

pub fn open_raw<P: AsRef<Path>>(path: P) -> Result<File>

Open a non indexed file and generates the index.

Source

pub fn open_custom<P: AsRef<Path>>(path: P, index: Arc<Index>) -> Result<File>

Open a non indexed file and uses a custom index index. Expects the index to be properly built.

Source

pub fn from_buf_reader(reader: BufReader<File>, index: Arc<Index>) -> File

Creates a new File using an existing _std::io::BufReader and index

Source

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

Read the whole file into a String

Trait Implementations§

Source§

impl Debug for File

Source§

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

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

impl Indexable for File

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 IndexableFile for File

Source§

fn read_current_line(&mut self, 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§

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

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

impl ReadByLine for File

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

impl TryInto<IndexedReader<String>> for File

Source§

fn try_into(self) -> Result<IndexedString>

Convert a file into an IndexedString using the files index and reading the files contents into the memory

Source§

type Error = Error

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

impl TryInto<IndexedReader<Vec<u8>>> for File

Source§

fn try_into(self) -> Result<IndexedReader<Vec<u8>>>

Convert a file into an IndexedReader<Vec> using the files index and reading the files contents into the memory

Source§

type Error = Error

The type returned in the event of a conversion error.

Auto Trait Implementations§

§

impl Freeze for File

§

impl RefUnwindSafe for File

§

impl Send for File

§

impl Sync for File

§

impl Unpin for File

§

impl UnwindSafe for File

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.