Trait Encode

Source
pub trait Encode {
    // Required method
    fn encode<W>(&self, writer: &mut W) -> Result<(), Error>
       where W: FeltWriter;
}
Expand description

Any type that can be serialized into a series of Felts. This trait corresponds to the serialize function of the Cairo Serde trait.

This trait can be derived as long as all the fields in type implement Encode.

§Example

This example demonstrates deriving the trait and then using it to serialize an instance into Vec<Felt>.

use starknet_core::codec::Encode;

#[derive(Encode)]
struct CairoType {
    a: u32,
    b: Option<bool>,
}

let instance = CairoType {
    a: 3,
    b: Some(true),
};
let mut serialized = vec![];
instance.encode(&mut serialized);

assert_eq!(vec![Felt::THREE, Felt::ZERO, Felt::ONE], serialized);

Required Methods§

Source

fn encode<W>(&self, writer: &mut W) -> Result<(), Error>
where W: FeltWriter,

Converts the type into a list of Felt and append them into the writer.

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 Encode for bool

Source§

fn encode<W>(&self, writer: &mut W) -> Result<(), Error>
where W: FeltWriter,

Source§

impl Encode for i128

Source§

fn encode<W>(&self, writer: &mut W) -> Result<(), Error>
where W: FeltWriter,

Source§

impl Encode for u8

Source§

fn encode<W>(&self, writer: &mut W) -> Result<(), Error>
where W: FeltWriter,

Source§

impl Encode for u16

Source§

fn encode<W>(&self, writer: &mut W) -> Result<(), Error>
where W: FeltWriter,

Source§

impl Encode for u32

Source§

fn encode<W>(&self, writer: &mut W) -> Result<(), Error>
where W: FeltWriter,

Source§

impl Encode for u64

Source§

fn encode<W>(&self, writer: &mut W) -> Result<(), Error>
where W: FeltWriter,

Source§

impl Encode for u128

Source§

fn encode<W>(&self, writer: &mut W) -> Result<(), Error>
where W: FeltWriter,

Source§

impl<T> Encode for Option<T>
where T: Encode,

Source§

fn encode<W>(&self, writer: &mut W) -> Result<(), Error>
where W: FeltWriter,

Source§

impl<T> Encode for [T]
where T: Encode,

Source§

fn encode<W>(&self, writer: &mut W) -> Result<(), Error>
where W: FeltWriter,

Source§

impl<T> Encode for Vec<T>
where T: Encode,

Source§

fn encode<W>(&self, writer: &mut W) -> Result<(), Error>
where W: FeltWriter,

Source§

impl<T, const N: usize> Encode for [T; N]
where T: Encode,

Source§

fn encode<W>(&self, writer: &mut W) -> Result<(), Error>
where W: FeltWriter,

Implementors§

Source§

impl Encode for AddrValue

Source§

impl Encode for ContinuousPageHeader

Source§

impl Encode for FriConfigWithSerde

Source§

impl Encode for FriLayerQuery

Source§

impl Encode for FriLayerWitness

Source§

impl Encode for FriUnsentCommitmentWithSerde

Source§

impl Encode for FriVerificationStateConstant

Source§

impl Encode for FriVerificationStateVariable

Source§

impl Encode for FriWitnessWithSerde

Source§

impl Encode for ProofOfWorkConfigWithSerde

Source§

impl Encode for ProofOfWorkUnsentCommitmentWithSerde

Source§

impl Encode for PublicInputWithSerde

Source§

impl Encode for SegmentInfo

Source§

impl Encode for StarkConfigWithSerde

Source§

impl Encode for StarkProofWithSerde

Source§

impl Encode for StarkUnsentCommitmentWithSerde

Source§

impl Encode for StarkWitnessWithSerde

Source§

impl Encode for TableCommitment

Source§

impl Encode for TableCommitmentConfig

Source§

impl Encode for TableCommitmentConfigWithSerde

Source§

impl Encode for TableCommitmentWitness

Source§

impl Encode for TableCommitmentWitnessWithSerde

Source§

impl Encode for TableDecommitmentWithSerde

Source§

impl Encode for TracesConfigWithSerde

Source§

impl Encode for TracesDecommitmentWithSerde

Source§

impl Encode for TracesUnsentCommitmentWithSerde

Source§

impl Encode for TracesWitnessWithSerde

Source§

impl Encode for VectorCommitment

Source§

impl Encode for VectorCommitmentConfig

Source§

impl Encode for VectorCommitmentConfigWithSerde

Source§

impl Encode for VectorCommitmentWitness

Source§

impl Encode for VectorCommitmentWitnessWithSerde

Source§

impl Encode for VerifierConfiguration

Source§

impl Encode for VerifyProofFinalAndRegisterFactCall

Source§

impl Encode for VerifyProofInitialCall

Source§

impl Encode for VerifyProofStepCall

Source§

impl Encode for ByteArray

Source§

impl Encode for U256

Source§

impl Encode for Felt