Trait tsyncp::util::codec::DecodeMethod
source · pub trait DecodeMethod<T> {
type Error: 'static + Error;
// Required method
fn decode(bytes: BytesMut) -> Result<T, Self::Error>;
}Expand description
Trait for decoding given bytes into an item.
Generic parameter T is the data that will be decoded.
When implementing this trait, you can specify trait requirements for T, so that,
any types that implements that trait will be able to be decoded.
§Example
Below example will deserialize any item that implements serde::de::DeserializeOwned from json bytes.
use tsyncp::util::codec::DecodeMethod;
use bytes::BytesMut;
pub struct MyCustomCodec;
impl<T: serde::de::DeserializeOwned> DecodeMethod<T> for MyCustomCodec {
type Error = serde_json::Error;
fn decode(bytes: BytesMut) -> Result<T, Self::Error> {
serde_json::from_slice(bytes.as_ref())
}
}Required Associated Types§
Required Methods§
Object Safety§
This trait is not object safe.