nu_plugin_core

Trait Encoder

Source
pub trait Encoder<T>:
    Clone
    + Send
    + Sync {
    // Required methods
    fn encode(
        &self,
        data: &T,
        writer: &mut impl Write,
    ) -> Result<(), ShellError>;
    fn decode(&self, reader: &mut impl BufRead) -> Result<Option<T>, ShellError>;
}
Expand description

Encoder for a specific message type. Usually implemented on PluginInput and PluginOutput.

Required Methods§

Source

fn encode(&self, data: &T, writer: &mut impl Write) -> Result<(), ShellError>

Serialize a value in the PluginEncoders format

Returns ShellError::IOError if there was a problem writing, or ShellError::PluginFailedToEncode for a serialization error.

Source

fn decode(&self, reader: &mut impl BufRead) -> Result<Option<T>, ShellError>

Deserialize a value from the PluginEncoder’s format

Returns None if there is no more output to receive.

Returns ShellError::IOError if there was a problem reading, or ShellError::PluginFailedToDecode for a deserialization error.

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§