pub trait Codec<T>: Links {
type Error;
const CODE: u64;
// Required methods
fn decode<R: BufRead>(reader: R) -> Result<T, Self::Error>;
fn encode<W: Write>(writer: W, data: &T) -> Result<(), Self::Error>;
// Provided methods
fn decode_from_slice(bytes: &[u8]) -> Result<T, Self::Error> { ... }
fn encode_to_vec(data: &T) -> Result<Vec<u8>, Self::Error> { ... }
}Expand description
Each IPLD codec implementation should implement this Codec trait. This way codecs can be more easily exchanged or combined.
Required Associated Constants§
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn decode_from_slice(bytes: &[u8]) -> Result<T, Self::Error>
fn decode_from_slice(bytes: &[u8]) -> Result<T, Self::Error>
Decode a slice into the desired type.
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.