pub trait BytesCodec {
// Required methods
fn to_bytes(self) -> Bytes;
fn from_bytes(bytes: &Bytes) -> Self;
}Expand description
A trait for converting types to and from Bytes.
This trait provides methods to convert a type into a Bytes object,
as well as reconstruct the original type from a Bytes object.
§Examples
use alloy::primitives::Address;
use tycho_ethereum::BytesCodec;
use tycho_common::Bytes;
let address_value = Address::ZERO;
let bytes: Bytes = address_value.to_bytes(); // Converts Address to Bytes
let new_address = Address::from_bytes(&bytes); // Converts Bytes back to AddressRequired Methods§
Sourcefn from_bytes(bytes: &Bytes) -> Self
fn from_bytes(bytes: &Bytes) -> Self
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.