pub trait Block: Default {
// Required methods
fn start(&mut self, input: Value) -> Command;
fn step(&mut self, event: Event) -> Command;
// Provided method
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§
Sourcefn start(&mut self, input: Value) -> Command
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.
Provided Methods§
Sourcefn on_token(&mut self, _token: &str) -> TokenAction
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".