pub trait Encode<M> {
// Required method
fn encode<E>(&self, cx: &E::Cx, encoder: E) -> Result<E::Ok, E::Error>
where E: Encoder<Mode = M>;
}
Expand description
Trait governing how types are encoded.
This is typically implemented automatically using the Encode
derive.
§Examples
use musli::Encode;
#[derive(Encode)]
struct MyType {
data: [u8; 128],
}
Implementing manually:
use musli::{Encode, Encoder};
struct MyType {
data: [u8; 128],
}
impl<M> Encode<M> for MyType {
fn encode<E>(&self, cx: &E::Cx, encoder: E) -> Result<E::Ok, E::Error>
where
E: Encoder<Mode = M>,
{
encoder.encode_array(&self.data)
}
}
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.