Decode

Trait Decode 

Source
pub trait Decode<'a>: Sized {
    // Required method
    fn decode_iter<T>(iter: &mut T) -> Result<Self, Error>
       where T: Iterator<Item = &'a Felt>;

    // Provided method
    fn decode<T>(reader: T) -> Result<Self, Error>
       where T: IntoIterator<Item = &'a Felt> { ... }
}
Expand description

Any type that can be deserialized from a series of Felts. This trait corresponds to the deserialize 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 deserialize an instance from Vec<Felt>.

use starknet_core::codec::Decode;

#[derive(Debug, PartialEq, Eq, Decode)]
struct CairoType {
    a: u32,
    b: Option<bool>,
}

assert_eq!(
    CairoType {
        a: 3,
        b: Some(true)
    },
    CairoType::decode(&[Felt::THREE, Felt::ZERO, Felt::ONE]).unwrap()
);

Required Methods§

Source

fn decode_iter<T>(iter: &mut T) -> Result<Self, Error>
where T: Iterator<Item = &'a Felt>,

Converts into the type from an iterator of references to Felt.

Provided Methods§

Source

fn decode<T>(reader: T) -> Result<Self, Error>
where T: IntoIterator<Item = &'a Felt>,

Converts into the type from a list of Felt.

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<'a> Decode<'a> for bool

Source§

fn decode_iter<T>(iter: &mut T) -> Result<Self, Error>
where T: Iterator<Item = &'a Felt>,

Source§

impl<'a> Decode<'a> for i128

Source§

fn decode_iter<T>(iter: &mut T) -> Result<Self, Error>
where T: Iterator<Item = &'a Felt>,

Source§

impl<'a> Decode<'a> for u8

Source§

fn decode_iter<T>(iter: &mut T) -> Result<Self, Error>
where T: Iterator<Item = &'a Felt>,

Source§

impl<'a> Decode<'a> for u16

Source§

fn decode_iter<T>(iter: &mut T) -> Result<Self, Error>
where T: Iterator<Item = &'a Felt>,

Source§

impl<'a> Decode<'a> for u32

Source§

fn decode_iter<T>(iter: &mut T) -> Result<Self, Error>
where T: Iterator<Item = &'a Felt>,

Source§

impl<'a> Decode<'a> for u64

Source§

fn decode_iter<T>(iter: &mut T) -> Result<Self, Error>
where T: Iterator<Item = &'a Felt>,

Source§

impl<'a> Decode<'a> for u128

Source§

fn decode_iter<T>(iter: &mut T) -> Result<Self, Error>
where T: Iterator<Item = &'a Felt>,

Source§

impl<'a, T> Decode<'a> for Option<T>
where T: Decode<'a>,

Source§

fn decode_iter<I>(iter: &mut I) -> Result<Self, Error>
where I: Iterator<Item = &'a Felt>,

Source§

impl<'a, T, const N: usize> Decode<'a> for [T; N]
where T: Decode<'a> + Sized,

Source§

fn decode_iter<I>(iter: &mut I) -> Result<Self, Error>
where I: Iterator<Item = &'a Felt>,

Implementors§

Source§

impl<'a> Decode<'a> for ByteArray

Source§

impl<'a> Decode<'a> for Felt

Source§

impl<'a> Decode<'a> for U256

Source§

impl<'a, T> Decode<'a> for Vec<T>
where T: Decode<'a>,