Skip to main content

Execution

Struct Execution 

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

Source

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.

Source

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.

Auto Trait Implementations§

§

impl<'a, 'p> !RefUnwindSafe for Execution<'a, 'p>

§

impl<'a, 'p> !UnwindSafe for Execution<'a, 'p>

§

impl<'a, 'p> Forget for Execution<'a, 'p>

§

impl<'a, 'p> Freeze for Execution<'a, 'p>

§

impl<'a, 'p> Move for Execution<'a, 'p>

§

impl<'a, 'p> Send for Execution<'a, 'p>

§

impl<'a, 'p> Sync for Execution<'a, 'p>

§

impl<'a, 'p> Unpin for Execution<'a, 'p>

§

impl<'a, 'p> UnsafeUnpin for Execution<'a, 'p>

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.