Skip to main content

EffectSink

Trait EffectSink 

Source
pub trait EffectSink {
    // Required methods
    fn write(&mut self, channel: ChannelId, bytes: &[u8]);
    fn log(&mut self, level: LogLevel, stage: &str, message: &str);

    // Provided methods
    fn pace(&mut self, delay: Duration) { ... }
    fn halt(&mut self, stage: &str, reason: &str) { ... }
}
Expand description

Collects the side effects a plugin asks for during one call.

The host implements this over per-channel staging buffers, so a side write is an extend_from_slice and nothing else. Staged bytes are flushed to their sinks concurrently with the downstream write.

Required Methods§

Source

fn write(&mut self, channel: ChannelId, bytes: &[u8])

Source

fn log(&mut self, level: LogLevel, stage: &str, message: &str)

stage is the emitting stage’s display name, so the host can tag the line without every plugin having to repeat itself.

Provided Methods§

Source

fn pace(&mut self, delay: Duration)

Wait delay before reading upstream again.

The one effect that acts on the reader rather than on a side channel. A stage cannot sleep: it is synchronous, it runs on the reading task, and a guest has no runtime to sleep on. So it asks, and the host holds off its next read. Several stages asking on one chunk get the longest of the requests, not the sum.

Defaults to doing nothing, so a host that has no reader to hold (a test harness, an offline driver) is not obliged to honour it.

Source

fn halt(&mut self, stage: &str, reason: &str)

Stop reading upstream, as if it had just reached end of stream.

Everything already emitted is still written, on_eof still cascades, and the path closes down its normal way. This is how a stage ends a transfer deliberately, which is not a failure and must not be reported as one.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§