Skip to main content

ReassemblyStorage

Enum ReassemblyStorage 

Source
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§

§

InMemory(Vec<u8>)

Data held in memory.

§

OnDisk

Data flushed to a memory-mapped temporary file.

Fields

§len: usize

Implementations§

Source§

impl ReassemblyStorage

Source

pub fn new() -> Self

Create new empty in-memory storage.

Source

pub fn len(&self) -> usize

Current byte length of stored data.

Source

pub fn is_empty(&self) -> bool

Whether storage is empty.

Source

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.

Source

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.

Source

pub fn read_all(&self) -> Result<Vec<u8>>

Read all data back. Works for both in-memory and on-disk storage.

Source

pub fn as_slice(&self) -> Option<&[u8]>

Get a reference to in-memory data. Returns None if spilled.

Source

pub fn is_spilled(&self) -> bool

Whether data is currently on disk.

Source

pub fn in_memory_bytes(&self) -> usize

Bytes currently held in memory (0 if spilled).

Source

pub fn truncate(&mut self, max_len: usize)

Truncate stored data to at most max_len bytes.

For in-memory storage, truncates the Vec. For on-disk storage, only updates the tracked length (the file is not physically truncated).

Source

pub fn drain(&mut self) -> Result<Vec<u8>>

Drain and return data, resetting to empty. Reads from disk if spilled.

Trait Implementations§

Source§

impl Debug for ReassemblyStorage

Source§

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

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

impl Default for ReassemblyStorage

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V