nu_plugin_core

Trait 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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§