Struct buffered_reader::File

source ·
pub struct File<'a, C: Debug + Sync + Send>(/* private fields */);
Expand description

Wraps files using mmap().

This implementation tries to mmap the file, falling back to just using a generic reader.

Implementations§

source§

impl<'a> File<'a, ()>

source

pub fn new<P: AsRef<Path>>(file: File, path: P) -> Result<Self>

Wraps a fs::File.

The given path should be the path that has been used to obtain file from. It is used in error messages to provide context to the user.

While this is slightly less convenient than Self::open, it allows one to inspect or manipulate the fs::File object before handing it off. For example, one can inspect the metadata.

source

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

Opens the given file.

source§

impl<'a, C: Debug + Sync + Send> File<'a, C>

Like Self::new, but sets a cookie.

The given path should be the path that has been used to obtain file from. It is used in error messages to provide context to the user.

While this is slightly less convenient than Self::with_cookie, it allows one to inspect or manipulate the fs::File object before handing it off. For example, one can inspect the metadata.

Like Self::open, but sets a cookie.

Trait Implementations§

source§

impl<'a, C: Debug + Sync + Send> BufferedReader<C> for File<'a, C>

source§

fn buffer(&self) -> &[u8]

Returns a reference to the internal buffer. Read more
source§

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

Ensures that the internal buffer has at least amount bytes of data, and returns it. Read more
source§

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

Like BufferedReader::data, but returns an error if there is not at least amount bytes available. Read more
source§

fn consume(&mut self, amount: usize) -> &[u8]

Consumes some of the data. Read more
source§

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

A convenience function that combines BufferedReader::data and BufferedReader::consume. Read more
source§

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

A convenience function that effectively combines BufferedReader::data_hard and BufferedReader::consume. Read more
source§

fn get_mut(&mut self) -> Option<&mut dyn BufferedReader<C>>

Returns a mutable reference to the inner BufferedReader, if any. Read more
source§

fn get_ref(&self) -> Option<&dyn BufferedReader<C>>

Returns a reference to the inner BufferedReader, if any.
source§

fn into_inner<'b>(self: Box<Self>) -> Option<Box<dyn BufferedReader<C> + 'b>>where Self: 'b,

Returns the underlying reader, if any. Read more
source§

fn cookie_set(&mut self, cookie: C) -> C

Sets the BufferedReader’s cookie and returns the old value.
source§

fn cookie_ref(&self) -> &C

Returns a reference to the BufferedReader’s cookie.
source§

fn cookie_mut(&mut self) -> &mut C

Returns a mutable reference to the BufferedReader’s cookie.
source§

fn data_eof(&mut self) -> Result<&[u8], Error>

Returns all of the data until EOF. Like BufferedReader::data, this does not actually consume the data that is read. Read more
source§

fn eof(&mut self) -> bool

Checks whether the end of the stream is reached.
source§

fn consummated(&mut self) -> bool

Checks whether this reader is consummated. Read more
source§

fn read_be_u16(&mut self) -> Result<u16, Error>

A convenience function for reading a 16-bit unsigned integer in big endian format.
source§

fn read_be_u32(&mut self) -> Result<u32, Error>

A convenience function for reading a 32-bit unsigned integer in big endian format.
source§

fn read_to(&mut self, terminal: u8) -> Result<&[u8], Error>

Reads until either terminal is encountered or EOF. Read more
source§

fn drop_until(&mut self, terminals: &[u8]) -> Result<usize, Error>

Discards the input until one of the bytes in terminals is encountered. Read more
source§

fn drop_through( &mut self, terminals: &[u8], match_eof: bool ) -> Result<(Option<u8>, usize), Error>

Discards the input until one of the bytes in terminals is encountered. Read more
source§

fn steal(&mut self, amount: usize) -> Result<Vec<u8>, Error>

Like BufferedReader::data_consume_hard, but returns the data in a caller-owned buffer. Read more
source§

fn steal_eof(&mut self) -> Result<Vec<u8>, Error>

Like BufferedReader::steal, but instead of stealing a fixed number of bytes, steals all of the data until the end of file.
source§

fn drop_eof(&mut self) -> Result<bool, Error>

Like BufferedReader::steal_eof, but instead of returning the data, the data is discarded. Read more
source§

fn copy(&mut self, sink: &mut dyn Write) -> Result<u64>

Copies data to the given writer returning the copied amount. Read more
source§

fn dump(&self, sink: &mut dyn Write) -> Result<()>where Self: Sized,

A helpful debugging aid to pretty print a Buffered Reader stack. Read more
source§

fn into_boxed<'a>(self) -> Box<dyn BufferedReader<C> + 'a>where Self: 'a + Sized,

Boxes the reader.
source§

fn as_boxed<'a>(self) -> Box<dyn BufferedReader<C> + 'a>where Self: 'a + Sized,

👎Deprecated: Use into_boxed
Boxes the reader.
source§

impl<'a, C: Debug + Sync + Send> Debug for File<'a, C>

source§

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

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

impl<'a, C: Debug + Sync + Send> Display for File<'a, C>

source§

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

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

impl<'a, C: Debug + Sync + Send> Read for File<'a, C>

source§

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

Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
1.36.0 · source§

fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>

Like read, except that it reads into a slice of buffers. Read more
source§

fn is_read_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Reader has an efficient read_vectored implementation. Read more
1.0.0 · source§

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

Read all bytes until EOF in this source, placing them into buf. Read more
1.0.0 · source§

fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>

Read all bytes until EOF in this source, appending them to buf. Read more
1.6.0 · source§

fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>

Read the exact number of bytes required to fill buf. Read more
source§

fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Pull some bytes from this source into the specified buffer. Read more
source§

fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Read the exact number of bytes required to fill cursor. Read more
1.0.0 · source§

fn by_ref(&mut self) -> &mut Selfwhere Self: Sized,

Creates a “by reference” adaptor for this instance of Read. Read more
1.0.0 · source§

fn bytes(self) -> Bytes<Self>where Self: Sized,

Transforms this Read instance to an Iterator over its bytes. Read more
1.0.0 · source§

fn chain<R>(self, next: R) -> Chain<Self, R>where R: Read, Self: Sized,

Creates an adapter which will chain this stream with another. Read more
1.0.0 · source§

fn take(self, limit: u64) -> Take<Self>where Self: Sized,

Creates an adapter which will read at most limit bytes from it. Read more

Auto Trait Implementations§

§

impl<'a, C> !RefUnwindSafe for File<'a, C>

§

impl<'a, C> Send for File<'a, C>

§

impl<'a, C> Sync for File<'a, C>

§

impl<'a, C> Unpin for File<'a, C>where C: Unpin,

§

impl<'a, C> !UnwindSafe for File<'a, C>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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.