pub trait EncodeBytes<M> {
// Required method
fn encode_bytes<E>(&self, cx: &E::Cx, encoder: E) -> Result<E::Ok, E::Error>
where E: Encoder<Mode = M>;
}
Expand description
Trait governing how a type is encoded as bytes.
This is typically used automatically through the #[musli(bytes)]
attribute
through the Encode
derive.
§Examples
use musli::Encode;
#[derive(Encode)]
struct MyType {
#[musli(bytes)]
data: [u8; 128],
}
Implementing manually:
use musli::{Encode, Encoder};
use musli::en::EncodeBytes;
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,
{
self.data.encode_bytes(cx, encoder)
}
}
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.