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>
impl<R: ReadCacheOps> ReadCache<R>
sourcepub fn range(&self, offset: u64, size: u64) -> ReadCacheRange<'_, R>
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.
sourcepub fn into_inner(self) -> R
pub fn into_inner(self) -> R
Unwrap this ReadCache<R>
, returning the underlying reader.
Trait Implementations§
source§impl<'a, R: ReadCacheOps> ReadRef<'a> for &'a ReadCache<R>
impl<'a, R: ReadCacheOps> ReadRef<'a> for &'a ReadCache<R>
source§fn read_bytes_at(self, offset: u64, size: u64) -> Result<&'a [u8], ()>
fn read_bytes_at(self, offset: u64, size: u64) -> Result<&'a [u8], ()>
Get a reference to a
u8
slice at the given offset. Read moresource§fn read_bytes_at_until(
self,
range: Range<u64>,
delimiter: u8,
) -> Result<&'a [u8], ()>
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 moresource§fn read_bytes(self, offset: &mut u64, size: u64) -> Result<&'a [u8], ()>
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 moresource§fn read<T: Pod>(self, offset: &mut u64) -> Result<&'a T, ()>
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 moresource§fn read_at<T: Pod>(self, offset: u64) -> Result<&'a T, ()>
fn read_at<T: Pod>(self, offset: u64) -> Result<&'a T, ()>
Get a reference to a
Pod
type at the given offset. Read moreAuto 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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more