pub trait Decode<'de, M>: Sized {
// Required method
fn decode<D>(cx: &D::Cx, decoder: D) -> Result<Self, D::Error>
where D: Decoder<'de, Mode = M>;
}
Expand description
Trait governing how types are decoded.
This is typically implemented automatically using the Decode
derive.
§Examples
use musli::Decode;
#[derive(Decode)]
struct MyType {
data: [u8; 128],
}
Implementing manually:
use musli::{Decode, Decoder};
struct MyType {
data: [u8; 128],
}
impl<'de, M> Decode<'de, M> for MyType {
fn decode<D>(cx: &D::Cx, decoder: D) -> Result<Self, D::Error>
where
D: Decoder<'de>,
{
Ok(Self {
data: decoder.decode_array()?,
})
}
}
Required Methods§
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.