Trait nu_plugin_core::Interface

source ·
pub trait Interface: Clone + Send {
    type Output: From<StreamMessage>;
    type DataContext;

    // Required methods
    fn write(&self, output: Self::Output) -> Result<(), ShellError>;
    fn flush(&self) -> Result<(), ShellError>;
    fn stream_id_sequence(&self) -> &Sequence;
    fn stream_manager_handle(&self) -> &StreamManagerHandle;
    fn prepare_pipeline_data(
        &self,
        data: PipelineData,
        context: &Self::DataContext
    ) -> Result<PipelineData, ShellError>;

    // Provided method
    fn init_write_pipeline_data(
        &self,
        data: PipelineData,
        context: &Self::DataContext
    ) -> Result<(PipelineDataHeader, PipelineDataWriter<Self>), ShellError> { ... }
}
Expand description

An interface provides an API for communicating with a plugin or the engine and facilitates stream I/O. See PluginInterface in nu-plugin-engine for the API from the engine side to a plugin, or EngineInterface in nu-plugin for the API from the plugin side to the engine.

There can be multiple copies of the interface managed by a single InterfaceManager.

Required Associated Types§

source

type Output: From<StreamMessage>

The output message type, which must be capable of encapsulating a StreamMessage.

source

type DataContext

Any context required to construct PipelineData. Can be () if not needed.

Required Methods§

source

fn write(&self, output: Self::Output) -> Result<(), ShellError>

Write an output message.

source

fn flush(&self) -> Result<(), ShellError>

Flush the output buffer, so messages are visible to the other side.

source

fn stream_id_sequence(&self) -> &Sequence

Get the sequence for generating new StreamIds.

source

fn stream_manager_handle(&self) -> &StreamManagerHandle

Get the StreamManagerHandle for doing stream operations.

source

fn prepare_pipeline_data( &self, data: PipelineData, context: &Self::DataContext ) -> Result<PipelineData, ShellError>

Prepare PipelineData to be written. This is called by init_write_pipeline_data() as a hook so that values that need special handling can be taken care of.

Provided Methods§

source

fn init_write_pipeline_data( &self, data: PipelineData, context: &Self::DataContext ) -> Result<(PipelineDataHeader, PipelineDataWriter<Self>), ShellError>

Initialize a write for PipelineData. This returns two parts: the header, which can be embedded in the particular message that references the stream, and a writer, which will write out all of the data in the pipeline when .write() is called.

Note that not all PipelineData starts a stream. You should call write() anyway, as it will automatically handle this case.

This method is provided for implementors to use.

Object Safety§

This trait is not object safe.

Implementors§