SerdeBincodeCompat

Trait SerdeBincodeCompat 

Source
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;
}
Available on crate feature serde-bincode-compat only.
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§

Source

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§

Source

fn as_repr(&self) -> Self::BincodeRepr<'_>

Convert this type into its bincode representation

Source

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.

Implementations on Foreign Types§

Source§

impl SerdeBincodeCompat for EthereumTxEnvelope<TxEip4844>

Source§

type BincodeRepr<'a> = EthereumTxEnvelope<'a>

Source§

fn as_repr(&self) -> Self::BincodeRepr<'_>

Source§

fn from_repr(repr: Self::BincodeRepr<'_>) -> Self

Source§

impl SerdeBincodeCompat for OpTxEnvelope

Available on crate feature op only.
Source§

type BincodeRepr<'a> = OpTxEnvelope<'a>

Source§

fn as_repr(&self) -> Self::BincodeRepr<'_>

Source§

fn from_repr(repr: Self::BincodeRepr<'_>) -> Self

Source§

impl<T: SerdeBincodeCompat, H: SerdeBincodeCompat> SerdeBincodeCompat for Block<T, H>

Source§

type BincodeRepr<'a> = Block<'a, T, H>

Source§

fn as_repr(&self) -> Self::BincodeRepr<'_>

Source§

fn from_repr(repr: Self::BincodeRepr<'_>) -> Self

Source§

impl<T: SerdeBincodeCompat, H: SerdeBincodeCompat> SerdeBincodeCompat for BlockBody<T, H>

Source§

type BincodeRepr<'a> = BlockBody<'a, T, H>

Source§

fn as_repr(&self) -> Self::BincodeRepr<'_>

Source§

fn from_repr(repr: Self::BincodeRepr<'_>) -> Self

Implementors§