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§
Provided Methods§
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.