pub trait Decode: Sized {
// Required method
fn decode<D>(
decoder: &mut D,
plugin: &Plugin,
session: &mut Session,
) -> Result<Self, Error>
where D: Decoder + ?Sized;
}Expand description
A trait for types that can be deserialized.
Types implementing Decode can deserialize themselves using a
Decoder. The Plugin parameter allows passing additional context for
custom deserialization strategies.
§Example
ⓘ
struct Point {
x: i32,
y: i32,
}
impl Decode for Point {
fn decode<D: Decoder + ?Sized>(
decoder: &mut D,
plugin: &Plugin,
) -> io::Result<Self> {
let x = i32::decode(decoder, plugin)?;
let y = i32::decode(decoder, plugin)?;
Ok(Point { x, y })
}
}Required Methods§
Sourcefn decode<D>(
decoder: &mut D,
plugin: &Plugin,
session: &mut Session,
) -> Result<Self, Error>
fn decode<D>( decoder: &mut D, plugin: &Plugin, session: &mut Session, ) -> Result<Self, Error>
Decodes a value using the provided decoder.
§Arguments
decoder- The decoder to read fromplugin- Plugin context for custom deserialization strategiessession- Session state for managing deserialization context
§Errors
Returns an error if the underlying I/O operation fails or if the data is invalid.
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.