pub trait ValueEncoder<Input: ?Sized> {
type Output;
type Error;
// Required method
fn encode(&mut self, input: &Input) -> Result<Self::Output, Self::Error>;
}Expand description
Encodes a borrowed input value into an owned representation.
This trait is a convenience-layer API. Use crate::Codec for low-level
single-value buffer encoding and crate::Transcoder for batch
conversion over caller-provided buffers.
§Examples
use qubit_codec::ValueEncoder;
struct TextEncoder;
impl ValueEncoder<str> for TextEncoder {
type Output = Vec<u8>;
type Error = core::convert::Infallible;
fn encode(&mut self, input: &str) -> Result<Self::Output, Self::Error> {
Ok(input.as_bytes().to_vec())
}
}
let mut encoder = TextEncoder;
assert_eq!(encoder.encode("hello").unwrap(), b"hello");Required Associated Types§
Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".