pub struct Reader { /* private fields */ }Expand description
Zero-copy reader for accessing region data from memory-mapped storage.
Holds a lock on the memory map and a snapshot of region metadata. The metadata is cloned at reader creation time, providing snapshot isolation and avoiding lock ordering deadlocks with writers.
§Important: Lock Duration
Drop this reader as soon as possible. While held, this blocks:
set_min_len(file growth)compact/punch_holes(final sync phase)
Long-lived readers can cause other operations to hang waiting for the lock. If you need to keep data around, copy it out of the reader first.
The Reader owns references to the Database and Region to ensure the underlying data structures remain valid for the lifetime of the guards.
Implementations§
Source§impl Reader
impl Reader
Sourcepub fn unchecked_read(&self, offset: usize, len: usize) -> &[u8] ⓘ
pub fn unchecked_read(&self, offset: usize, len: usize) -> &[u8] ⓘ
Reads data from the region without bounds checking.
§Safety
The caller must ensure offset + len is within the region’s length.
Reading beyond the region’s bounds is undefined behavior.
Sourcepub fn read(&self, offset: usize, len: usize) -> &[u8] ⓘ
pub fn read(&self, offset: usize, len: usize) -> &[u8] ⓘ
Reads a slice of data from the region at the given offset.
§Panics
Panics if offset + len exceeds the region’s length.
Sourcepub fn prefixed(&self, offset: usize) -> &[u8] ⓘ
pub fn prefixed(&self, offset: usize) -> &[u8] ⓘ
Returns a slice from the offset to the end of the mmap.
This allows reading beyond the region boundary for performance-critical sequential access patterns, but the offset must still be within the region.
§Panics
Panics if the offset exceeds the region’s length.
Auto Trait Implementations§
impl Freeze for Reader
impl !RefUnwindSafe for Reader
impl !Send for Reader
impl Sync for Reader
impl Unpin for Reader
impl !UnwindSafe for Reader
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more