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§
Sourcefn encode(&self, data: &T, writer: &mut impl Write) -> Result<(), ShellError>
fn encode(&self, data: &T, writer: &mut impl Write) -> Result<(), ShellError>
Serialize a value in the PluginEncoder
s format
Returns ShellError::IOError
if there was a problem writing, or
ShellError::PluginFailedToEncode
for a serialization error.
Sourcefn decode(&self, reader: &mut impl BufRead) -> Result<Option<T>, ShellError>
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.