Skip to main content

Buffer

Enum Buffer 

Source
pub enum Buffer {
    InMemory(Vec<u8>),
    Spilled {
        writer: BufWriter<NamedTempFile>,
        len: u64,
    },
}
Expand description

The buffered input. Transitions from in-memory to spilled as data accumulates.

Variants§

§

InMemory(Vec<u8>)

In-memory accumulation (small inputs).

§

Spilled

Spilled-to-tempfile accumulation (large inputs).

Fields

§len: u64

Tracked size in bytes (since BufWriter writes are not all flushed yet).

Implementations§

Source§

impl Buffer

Source

pub fn new() -> Self

Construct an empty in-memory buffer with no preallocation.

Source

pub fn len(&self) -> u64

Return the current logical length of the buffered bytes.

Source

pub fn is_empty(&self) -> bool

True iff no bytes have been appended to this buffer.

Source

pub fn drain_reader<R: Read>( &mut self, reader: R, threshold: usize, spill_dir: &Path, ) -> Result<()>

Drain the entire reader into this buffer, transitioning to the spilled variant when the accumulated size would exceed threshold.

spill_dir is the directory in which the spill tempfile is created when the transition triggers. Caller MUST pass the target file’s parent directory (HINT-002).

On the binary path (feature cli), the loop polls the process-wide cancellation flag between chunks; if a signal was delivered, the drain returns io::ErrorKind::Interrupted so the in-progress tempfile is dropped via the normal Drop chain before exit.

Source

pub fn append( &mut self, bytes: &[u8], threshold: usize, spill_dir: &Path, ) -> Result<()>

Append a slice of bytes, transitioning to spilled storage if doing so would push the buffer past threshold.

Source

pub fn transition_to_spilled(&mut self, spill_dir: &Path) -> Result<()>

Promote an InMemory buffer to a Spilled one, flushing the existing bytes into the new tempfile. No-op if already spilled.

Source

pub fn write_to<W: Write>(self, out: W) -> Result<()>

Consume the buffer and write its bytes to out. Implementations:

  • InMemory: a single write_all of the Vec.
  • Spilled: flush BufWriter, rewind the NamedTempFile to start, copy through to out in 64 KiB chunks.

Trait Implementations§

Source§

impl Default for Buffer

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