Struct object::read::ReadCache

source ·
pub struct ReadCache<R: ReadCacheOps> { /* private fields */ }
Expand description

An implementation of ReadRef for data in a stream that implements Read + Seek.

Contains a cache of read-only blocks of data, allowing references to them to be returned. Entries in the cache are never removed. Entries are keyed on the offset and size of the read. Currently overlapping reads are considered separate reads.

This is primarily intended for environments where memory mapped files are not available or not suitable, such as WebAssembly.

Note that malformed files can cause the cache to grow much larger than the file size.

Implementations§

source§

impl<R: ReadCacheOps> ReadCache<R>

source

pub fn new(read: R) -> Self

Create an empty ReadCache for the given stream.

source

pub fn range(&self, offset: u64, size: u64) -> ReadCacheRange<'_, R>

Return an implementation of ReadRef that restricts reads to the given range of the stream.

source

pub fn clear(&mut self)

Free buffers used by the cache.

source

pub fn into_inner(self) -> R

Unwrap this ReadCache<R>, returning the underlying reader.

Trait Implementations§

source§

impl<R: Debug + ReadCacheOps> Debug for ReadCache<R>

source§

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

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

impl<'a, R: ReadCacheOps> ReadRef<'a> for &'a ReadCache<R>

source§

fn len(self) -> Result<u64, ()>

The total size of the block of data.
source§

fn read_bytes_at(self, offset: u64, size: u64) -> Result<&'a [u8], ()>

Get a reference to a u8 slice at the given offset. Read more
source§

fn read_bytes_at_until( self, range: Range<u64>, delimiter: u8, ) -> Result<&'a [u8], ()>

Get a reference to a delimited u8 slice which starts at range.start. Read more
source§

fn read_bytes(self, offset: &mut u64, size: u64) -> Result<&'a [u8], ()>

Get a reference to a u8 slice at the given offset, and update the offset. Read more
source§

fn read<T: Pod>(self, offset: &mut u64) -> Result<&'a T, ()>

Get a reference to a Pod type at the given offset, and update the offset. Read more
source§

fn read_at<T: Pod>(self, offset: u64) -> Result<&'a T, ()>

Get a reference to a Pod type at the given offset. Read more
source§

fn read_slice<T: Pod>( self, offset: &mut u64, count: usize, ) -> Result<&'a [T], ()>

Get a reference to a slice of a Pod type at the given offset, and update the offset. Read more
source§

fn read_slice_at<T: Pod>(self, offset: u64, count: usize) -> Result<&'a [T], ()>

Get a reference to a slice of a Pod type at the given offset. Read more

Auto Trait Implementations§

§

impl<R> !Freeze for ReadCache<R>

§

impl<R> !RefUnwindSafe for ReadCache<R>

§

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

§

impl<R> !Sync for ReadCache<R>

§

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

§

impl<R> UnwindSafe for ReadCache<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>,

§

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.