pub trait Encode: Sized {
// Required method
fn encode<W: Write>(&self, w: W) -> Result<usize, Error>;
// Provided method
fn encode_to_vec(&self) -> Result<Vec<u8>, Error>
where Self: Sealed { ... }
}
Expand description
A trait that can be encoded into an io::Write
stream.
Implementing this trait allows types to be encoded into an io::Write
stream,
which is useful for writing data to various destinations like files, buffers, and streams.
§Examples
use codeq::Encode;
let data = "hello".to_string();
let mut buf = Vec::new();
data.encode(&mut buf).unwrap();
assert_eq!(buf, b"\x00\x00\x00\x05hello");
Required Methods§
Provided 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.