Skip to main content

SpillWriter

Struct SpillWriter 

Source
pub struct SpillWriter { /* private fields */ }
Expand description

The push side of the spill loop: bytes handed over one slice at a time, held in memory up to the policy’s memory cap, then in a temp file, and refused past its hard limit. The one owner of those limits — SpillSource::materialize_from drives it from a reader, and a caller that sees the bytes go past on their way somewhere else (a tee) pushes them itself.

A refusal (Error::SpillLimitExceeded) or a temp-file failure leaves the writer unusable; nothing it held is ever handed out partially.

Implementations§

Source§

impl SpillWriter

Source

pub fn new(policy: &SpillPolicy) -> Result<Self>

An empty spool under policy. SpillPolicy::Off is refused at once, as SpillSource::materialize refuses it.

Source

pub fn len(&self) -> u64

Bytes accepted so far.

Source

pub fn is_empty(&self) -> bool

Whether nothing has been accepted yet.

Source

pub fn reserve(&mut self, additional: u64)

Reserves memory for additional more bytes, up to what the memory tier can still hold, so a payload of known size grows its buffer once rather than by doubling (which could leave it holding about twice what it keeps). A hint only: nothing is refused here.

Source

pub fn push(&mut self, bytes: &[u8]) -> Result<()>

Appends bytes, escalating to a temp file once the memory cap is passed, and refusing past the hard limit.

Source

pub fn finish(self) -> Result<SpillSource>

The bytes pushed, as a seekable source positioned at the start.

Trait Implementations§

Source§

impl Debug for SpillWriter

Source§

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

Formats the value using the given formatter. 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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.