Skip to main content

Block

Trait Block 

Source
pub trait Block: Default {
    // Required methods
    fn start(&mut self, input: Value) -> Command;
    fn step(&mut self, event: Event) -> Command;

    // Provided methods
    fn signature() -> Signature { ... }
    fn on_token(&mut self, _token: &str) -> TokenAction { ... }
}
Expand description

What a proc-block author implements.

The host calls start once with the job’s input, then step after each command it carries out, until the block returns Command::Done or Command::Fail.

Required Methods§

Source

fn start(&mut self, input: Value) -> Command

Produce the first command from the job’s input.

Prefer returning Command::Fail to panicking on malformed input: a panic becomes an opaque wasm trap, whereas a Fail carries a code and a message the caller can act on.

Source

fn step(&mut self, event: Event) -> Command

Produce the next command, given the result of the previous one.

Provided Methods§

Source

fn signature() -> Signature

What this block accepts and produces.

Declared here rather than in a file beside the block, so it cannot disagree with the code below it. The host reads this to typecheck a pipeline’s seams before running anything.

The default is permissive — JSON in, JSON out — so an existing block keeps working. That is deliberately the weakest useful answer: a pipeline of Json seams typechecks unconditionally, so a block that means to be composed should say something more specific.

Source

fn on_token(&mut self, _token: &str) -> TokenAction

Decide whether generation should continue, once per streamed token.

Defaults to TokenAction::Continue, so a block indifferent to streaming can ignore it. A token or two may still arrive after returning TokenAction::Stop, because the verdict has to travel back to the thread doing the generating.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§