Skip to content

Instantly share code, notes, and snippets.

@preveen-stack
Created May 7, 2023 16:21
Show Gist options
  • Save preveen-stack/58938d3edc8e42c4310e13371d4988db to your computer and use it in GitHub Desktop.
Save preveen-stack/58938d3edc8e42c4310e13371d4988db to your computer and use it in GitHub Desktop.
[dependencies]
quote = "1.0"
use quote::quote;

fn main() {
	let field1 = quote! { x: u32 };
	let field2 = quote! { y: u32 };

	let generated_code = quote! {
	    struct MyStruct {
		#field1,
		#field2,
	    }
	};

	println!("{}", generated_code);
}


    Finished dev [unoptimized + debuginfo] target(s) in 0.12s
     Running `target/debug/quote_example`
struct MyStruct { x : u32 , y : u32 , }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment