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§
Sourcetype Output: From<StreamMessage>
type Output: From<StreamMessage>
The output message type, which must be capable of encapsulating a StreamMessage
.
Sourcetype DataContext
type DataContext
Any context required to construct PipelineData
. Can be ()
if not needed.
Required Methods§
Sourcefn flush(&self) -> Result<(), ShellError>
fn flush(&self) -> Result<(), ShellError>
Flush the output buffer, so messages are visible to the other side.
Sourcefn stream_id_sequence(&self) -> &Sequence
fn stream_id_sequence(&self) -> &Sequence
Get the sequence for generating new StreamId
s.
Sourcefn stream_manager_handle(&self) -> &StreamManagerHandle
fn stream_manager_handle(&self) -> &StreamManagerHandle
Get the StreamManagerHandle
for doing stream operations.
Sourcefn prepare_pipeline_data(
&self,
data: PipelineData,
context: &Self::DataContext,
) -> Result<PipelineData, ShellError>
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§
Sourcefn init_write_pipeline_data(
&self,
data: PipelineData,
context: &Self::DataContext,
) -> Result<(PipelineDataHeader, PipelineDataWriter<Self>), ShellError>
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.