pub struct Execution<'a, 'p> { /* private fields */ }Expand description
A WritePlan being carried out, one piece of I/O at a time.
An Execution does no I/O. It tells its caller what to do next: read these
source bytes into this buffer, write these bytes to the output, or stop. The
caller performs that however it likes (blocking, async, from a state machine
of its own) and calls Execution::step again. The sink, the checking of every
byte against the plan’s structure, and the coalescing of reads all happen
inside step, so every way of running a plan behaves the same.
let mut run = plan.start();
loop {
match run.step(&mut NullSink)? {
Action::Read { offset, buf } => {
src.seek(SeekFrom::Start(offset))?;
src.read_exact(buf)?;
}
Action::Write(bytes) => out.write_all(bytes)?,
Action::Done => break,
_ => unreachable!(),
}
}WritePlan::execute is that loop.
Implementations§
Source§impl<'a, 'p> Execution<'a, 'p>
impl<'a, 'p> Execution<'a, 'p>
Sourcepub fn with_buffer_len(self, len: usize) -> Self
pub fn with_buffer_len(self, len: usize) -> Self
Use a buffer (the most bytes one Action::Read asks for) of len bytes,
at least 4 KiB. The default is 256 KiB, or the output size if that is
smaller. Call it before the first step.
Sourcepub fn step<S: Sink + ?Sized>(&mut self, sink: &mut S) -> Result<Action<'_>>
pub fn step<S: Sink + ?Sized>(&mut self, sink: &mut S) -> Result<Action<'_>>
Carry the plan one step further: do the sink’s part, check the bytes against the plan’s structure, and say what the caller must do next. Call it again when that is done. Errors are final.
Every byte of the output reaches sink once, in order, tagged with its
segment and role, before the Action::Write that carries it.