cainome-cairo-serde-derive

Crates.iocainome-cairo-serde-derive
lib.rscainome-cairo-serde-derive
version0.1.0
sourcesrc
created_at2025-02-07 02:23:55.989114+00
updated_at2025-02-07 02:23:55.989114+00
descriptionA derive macro to implement the `CairoSerde` trait on structs or enums.
homepagehttps://github.com/cartridge-gg/cainome
repositoryhttps://github.com/cartridge-gg/cainome
max_upload_size
id1546434
size11,896
(glihm)

documentation

https://github.com/cartridge-gg/cainome

README

Cairo Serde Derive

Implement the CairoSerde macro to derive the CairoSerde trait on your types. The expanded core uses the CairoSerde type from cainome-cairo-serde crate, which will need to be imported in the crate that uses this derive.

CairoSerde allows to serialize and deserialize cairo types to/from native rust types.

Example

#[derive(Debug, CairoSerde, PartialEq)]
struct ExampleSimple {
    x: Vec<Felt>,
    y: u32,
}

let example = ExampleSimple {
    x: vec![Felt::ZERO],
    y: 2,
};

let serialized = ExampleSimple::cairo_serialize(&example);

let offset = 0;
let deserialized = ExampleSimple::cairo_deserialize(&serialized, offset).unwrap();

assert_eq!(deserialized, example);
Commit count: 132

cargo fmt