pub struct EntryStream { /* private fields */ }Expand description
EntryStream provides a streaming interface over an EntryHandle.
This struct allows reading large entries in chunks instead of loading the entire entry into memory. It is useful when working with entries larger than available RAM.
§⚠️ Non Zero-Copy Warning
Unlike EntryHandle, this implementation performs memory copies.
Each call to read() copies a portion of the entry into a user-provided buffer.
For zero-copy access, use EntryHandle::as_slice() instead.
§Example Usage
use simd_r_drive::storage_engine::{DataStore, EntryHandle, EntryStream, traits::{DataStoreReader, DataStoreWriter}};
use std::io::Read;
use std::path::PathBuf;
use tempfile::tempdir;
let temp_dir = tempdir().expect("Failed to create temp dir");
let temp_path = temp_dir.path().join("test_storage.bin");
let data_store = DataStore::from(PathBuf::from(temp_path));
// Write some test data
data_store.write(b"test_key", b"test_data");
let entry_handle = data_store.read(b"test_key").unwrap().unwrap();
// Assume `entry_handle` is obtained from storage
let mut stream = EntryStream::from(entry_handle);
let mut buffer = vec![0; 4096]; // Read in 4KB chunks
while let Ok(bytes_read) = stream.read(&mut buffer) {
if bytes_read == 0 {
break; // EOF
}
// Replace this with actual processing logic
println!("Read {} bytes", bytes_read);
}Trait Implementations§
Source§impl From<EntryHandle> for EntryStream
impl From<EntryHandle> for EntryStream
Source§fn from(entry_handle: EntryHandle) -> Self
fn from(entry_handle: EntryHandle) -> Self
Converts an EntryHandle into an EntryStream.
This allows the entry’s data to be read incrementally instead of accessing the full slice in memory at once.
§⚠️ Non Zero-Copy Warning
- Streaming reads require memory copies.
- If you need direct access to the full entry without copying, use
EntryHandle::as_slice().
Source§impl Read for EntryStream
impl Read for EntryStream
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
- Returns
Ok(0)on EOF (no more data). - Reads up to
buf.len()bytes from the entry. - Moves the read position forward after each call.
§⚠️ Non Zero-Copy Warning
- This method copies data from the memory-mapped file into the buffer.
- Use
EntryHandle::as_slice()for zero-copy access.
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
Like
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
🔬This is a nightly-only experimental API. (
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
Reads all bytes until EOF in this source, placing them into
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
Reads all bytes until EOF in this source, appending them to
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
Reads the exact number of bytes required to fill
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
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>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
🔬This is a nightly-only experimental API. (
read_buf)Reads the exact number of bytes required to fill
cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Creates a “by reference” adapter for this instance of
Read. Read more1.0.0 · Source§fn chain<R>(self, next: R) -> Chain<Self, R>
fn chain<R>(self, next: R) -> Chain<Self, R>
Creates an adapter which will chain this stream with another. Read more
Auto Trait Implementations§
impl Freeze for EntryStream
impl RefUnwindSafe for EntryStream
impl Send for EntryStream
impl Sync for EntryStream
impl Unpin for EntryStream
impl UnsafeUnpin for EntryStream
impl UnwindSafe for EntryStream
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