pub enum ReassemblyStorage {
InMemory(Vec<u8>),
OnDisk {
file: NamedTempFile,
len: usize,
},
}Expand description
A handle to reassembly data that may be in memory or on disk.
When in memory, behaves like a Vec<u8>. When spilled, data lives in a
temporary file and is read back via mmap on demand. The temp file is
auto-deleted when this value is dropped.
Variants§
Implementations§
Source§impl ReassemblyStorage
impl ReassemblyStorage
Sourcepub fn extend_from_slice(&mut self, data: &[u8])
pub fn extend_from_slice(&mut self, data: &[u8])
Append data. Works for both in-memory and on-disk storage.
When in-memory, appends to the Vec. When on-disk, appends to the
temporary file and updates the tracked length.
Sourcepub fn spill_to_disk(&mut self, spill_dir: Option<&Path>) -> Result<usize>
pub fn spill_to_disk(&mut self, spill_dir: Option<&Path>) -> Result<usize>
Spill in-memory data to disk, returning the number of bytes freed.
If already on disk or empty, returns 0.
Sourcepub fn read_all(&self) -> Result<Vec<u8>>
pub fn read_all(&self) -> Result<Vec<u8>>
Read all data back. Works for both in-memory and on-disk storage.
Sourcepub fn as_slice(&self) -> Option<&[u8]>
pub fn as_slice(&self) -> Option<&[u8]>
Get a reference to in-memory data. Returns None if spilled.
Sourcepub fn is_spilled(&self) -> bool
pub fn is_spilled(&self) -> bool
Whether data is currently on disk.
Sourcepub fn in_memory_bytes(&self) -> usize
pub fn in_memory_bytes(&self) -> usize
Bytes currently held in memory (0 if spilled).
Trait Implementations§
Source§impl Debug for ReassemblyStorage
impl Debug for ReassemblyStorage
Auto Trait Implementations§
impl Freeze for ReassemblyStorage
impl RefUnwindSafe for ReassemblyStorage
impl Send for ReassemblyStorage
impl Sync for ReassemblyStorage
impl Unpin for ReassemblyStorage
impl UnsafeUnpin for ReassemblyStorage
impl UnwindSafe for ReassemblyStorage
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
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>
Converts
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>
Converts
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