pub trait Codec:
Default
+ Send
+ Sync
+ Sized
+ 'static {
// Required methods
fn encode<T: Serialize>(&self, task: &T) -> Result<Vec<u8>, ()>;
fn encode_into<T: Serialize>(
&self,
task: &T,
buf: &mut Vec<u8>,
) -> Result<usize, ()>;
fn decode<'a, T: Deserialize<'a>>(&self, buf: &'a [u8]) -> Result<T, ()>;
}Expand description
The codec is immutable, if need changing (like setting up cipher), should have inner mutablilty
Required Methods§
fn encode<T: Serialize>(&self, task: &T) -> Result<Vec<u8>, ()>
Sourcefn encode_into<T: Serialize>(
&self,
task: &T,
buf: &mut Vec<u8>,
) -> Result<usize, ()>
fn encode_into<T: Serialize>( &self, task: &T, buf: &mut Vec<u8>, ) -> Result<usize, ()>
sererialized the msg into buf (with std::io::Writer), and return the size written
fn decode<'a, T: Deserialize<'a>>(&self, buf: &'a [u8]) -> Result<T, ()>
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.