Skip to main content

Crate ssz_derive

Crate ssz_derive 

Source
Expand description

Derive macros for SSZ Encode, Decode, and HashTreeRoot traits.

§Struct example

#[derive(Encode, Decode, HashTreeRoot)]
struct MyStruct {
    fixed_field: u32,
    var_field: ssz::List<u8, 1024>,
    #[ssz(skip)]
    cached: u64,
}

§Newtype passthrough

#[derive(Encode, Decode, HashTreeRoot)]
struct SlotIdx(#[ssz(transparent)] NonZeroU32);

§Enum example (SSZ Union)

#[derive(Encode, Decode, HashTreeRoot)]
enum Cap {
    #[ssz(selector = 0)]
    Instance(InstanceCap),
    #[ssz(selector = 1)]
    Image(ImageCap),
}

Derive Macros§

Decode
Derive the ssz::Decode trait for a struct or enum.
Encode
Derive the ssz::Encode trait for a struct or enum.
HashTreeRoot
Derive the ssz::HashTreeRoot trait for a struct or enum.