pub trait ValueDecoder<Input: ?Sized> {
type Output;
type Error;
// Required method
fn decode(&mut self, input: &Input) -> Result<Self::Output, Self::Error>;
}Expand description
Decodes a borrowed input value into an owned representation.
This trait is a convenience-layer API. Use crate::Codec for low-level
single-value buffer decoding and crate::Transcoder for batch
conversion over caller-provided buffers.
§Type Parameters
Input: Borrowed source type accepted bydecode. It may be unsized, so implementations can accept slices and string types without an extra reference layer.
§Examples
use core::convert::Infallible;
use qubit_codec::ValueDecoder;
struct Identity;
impl ValueDecoder<str> for Identity {
type Output = String;
type Error = Infallible;
fn decode(&mut self, input: &str) -> Result<Self::Output, Self::Error> {
Ok(input.to_owned())
}
}
let mut decoder = Identity;
assert_eq!(decoder.decode("hello").unwrap(), "hello");Required Associated Types§
Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".