Skip to main content

FileReadAt

Struct FileReadAt 

Source
pub struct FileReadAt { /* private fields */ }
Expand description

ReadAt over a file, using positional reads on Unix and Windows and seek + read elsewhere. Unix reads leave a shared file cursor unchanged; Windows seek_read can update it. No implementation uses unsafe.

The caller must keep the opened file’s bytes stable for the decoder operation. This adapter captures its length but neither locks the file nor detects every in-place replacement. An open handle and positional reads do not establish the coherent-representation contract of ReadAt.

Implementations§

Source§

impl FileReadAt

Source

pub fn new(file: File) -> Result<Self, StdSourceError>

Create a source over an already-open file.

Source

pub fn open(path: impl AsRef<Path>) -> Result<Self, StdSourceError>

Open path and create a source over it.

Trait Implementations§

Source§

impl ReadAt for FileReadAt

Source§

type Error = StdSourceError

The source-specific error type.
Source§

fn len(&mut self) -> Result<u64, Self::Error>

Total length in bytes. May be expensive: a buffered stream source consumes to the end of the stream to answer it. Callers that only read forward use read_at, which reports the end by returning fewer bytes, and never need this.
Source§

fn len_hint(&self) -> Option<u64>

Total length if it is known without reading ahead. Default None.
Source§

fn read_exact_at( &mut self, offset: u64, out: &mut [u8], ) -> Result<(), Self::Error>

Fill out with the bytes at offset. Fails rather than returning a short read.
Source§

fn is_empty(&mut self) -> Result<bool, Self::Error>

Whether the source is empty.
Source§

fn read_at(&mut self, offset: u64, out: &mut [u8]) -> Result<usize, Self::Error>

Read up to out.len() bytes at offset; returns the count, which is smaller only where the source ends (zero at or past the end). Read more
Source§

fn read_many_at( &mut self, reqs: &mut [(u64, &mut [u8])], ) -> Result<(), Self::Error>

Fill each buffer from its offset. The default serves requests in the order given; concurrent sources override to overlap them.
Source§

fn as_slice(&self) -> Option<&[u8]>

The whole source as one slice, when it is already in memory. Drivers and codecs use it to read without copying. Default None.

Auto Trait Implementations§

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.