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
impl SpillWriter
Sourcepub fn new(policy: &SpillPolicy) -> Result<Self>
pub fn new(policy: &SpillPolicy) -> Result<Self>
An empty spool under policy. SpillPolicy::Off is refused at once,
as SpillSource::materialize refuses it.
Sourcepub fn reserve(&mut self, additional: u64)
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.
Sourcepub fn push(&mut self, bytes: &[u8]) -> Result<()>
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.
Sourcepub fn finish(self) -> Result<SpillSource>
pub fn finish(self) -> Result<SpillSource>
The bytes pushed, as a seekable source positioned at the start.