Trait SerdeBincodeCompat
pub trait SerdeBincodeCompat: Sized + 'static {
type BincodeRepr<'a>: Debug + Serialize + DeserializeOwned;
// Required methods
fn as_repr(&self) -> Self::BincodeRepr<'_>;
fn from_repr(repr: Self::BincodeRepr<'_>) -> Self;
}
Expand description
Trait for types that can be serialized and deserialized using bincode.
This trait provides a workaround for bincode’s incompatibility with optional serde fields. It ensures all fields are serialized, making the type bincode-compatible.
§Implementation
The easiest way to implement this trait is using RlpBincode
for RLP-encodable types:
impl RlpBincode for MyType {}
// SerdeBincodeCompat is automatically implemented
For custom implementations, see the examples in the block
module.
The recommended way to add bincode compatible serialization is via the
serde_with
crate and the serde_as
macro. See for reference header
.
Required Associated Types§
type BincodeRepr<'a>: Debug + Serialize + DeserializeOwned
type BincodeRepr<'a>: Debug + Serialize + DeserializeOwned
Serde representation of the type for bincode serialization.
This type defines the bincode compatible serde format for the type.
Required Methods§
fn as_repr(&self) -> Self::BincodeRepr<'_>
fn as_repr(&self) -> Self::BincodeRepr<'_>
Convert this type into its bincode representation
fn from_repr(repr: Self::BincodeRepr<'_>) -> Self
fn from_repr(repr: Self::BincodeRepr<'_>) -> Self
Convert from the bincode representation
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.