From 6e3ef85fd7b9e2e97583105a28a5a863527cfe59 Mon Sep 17 00:00:00 2001 From: Kamen Mladenov Date: Tue, 28 Jan 2025 13:04:02 +0200 Subject: feat(zkvms_host_io): Generate input type from string and read input data from TOML file --- zkvms_host_io/input_macros/src/lib.rs | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 zkvms_host_io/input_macros/src/lib.rs (limited to 'zkvms_host_io/input_macros/src/lib.rs') diff --git a/zkvms_host_io/input_macros/src/lib.rs b/zkvms_host_io/input_macros/src/lib.rs new file mode 100644 index 0000000..51fd613 --- /dev/null +++ b/zkvms_host_io/input_macros/src/lib.rs @@ -0,0 +1,36 @@ +use proc_macro::TokenStream; + +#[path = "../../../guests_macro/src/parse_fn.rs"] +mod parse_fn; +use crate::parse_fn::{ args_split, args_divide, group_streams }; + + +fn get_args() -> TokenStream { + "(graph: Vec>, colors: u32, coloring: Vec>,)".parse::().unwrap() +} + +#[proc_macro] +pub fn generate_input_struct(_: TokenStream) -> TokenStream { + let args = &get_args(); + let all_args = args_split(&args); + + let mut struct_def = "#[derive(Debug, Serialize, Deserialize)] pub struct Input {".to_string(); + for arg in all_args { + struct_def += &format!("pub {arg},"); + } + + let (patterns, types) = args_divide(&args); + let types = group_streams(&types); + struct_def += &format!("}} + impl From for {types} {{ + fn from(input: Input) -> {types} {{ + ( + "); + + for field in patterns { + struct_def += &format!("input.{field},"); + } + struct_def += ") } }"; + + struct_def.parse::().unwrap() +} -- cgit v1.2.3