TritonVM / tasm-lib

A collection of functions written in Triton VM assembly (tasm)
Apache License 2.0
11 stars 2 forks source link

add proc macro: derive `tasm-lib`'s `StructType` from the actual struct #79

Open jan-ferdinand opened 9 months ago

jan-ferdinand commented 9 months ago

Current:

struct MyStruct {
    field_0: u32,
    field_1: BFieldElement,
    field_2: Vec<Digest>,
}

/// Don't forget to keep me in sync manually!
fn the_type() -> StructType {
    let name = "MyStruct".to_string();
    let fields = vec![
        ("field_0: u32,".to_string(), DataType::U32),
        ("field_1: BFieldElement,".to_string(), DataType::Bfe),
        ("field_2: Vec<Digest>,".to_string(), DataType::List(Box::new(DataType::Digest))),
    ];

    StructType { name, fields }
}

Desired:

#[derive(TasmLibType)] // <- derives the `StructType`
struct MyStruct {
    field_0: u32,
    field_1: BFieldElement,
    field_2: Vec<Digest>,
}