riptc_bridge_macros/
lib.rs1use proc_macro::TokenStream;
2
3#[proc_macro_derive(Riptc)]
8pub fn riptc_marker(input: TokenStream) -> TokenStream {
9 let mut tokens = input.into_iter().peekable();
12 let mut found_struct_or_enum = false;
13 let type_name = loop {
14 if let Some(token) = tokens.next() {
15 if let proc_macro::TokenTree::Ident(ident) = &token {
16 let ident_str = ident.to_string();
17 if ident_str == "struct" || ident_str == "enum" {
18 found_struct_or_enum = true;
19 } else if found_struct_or_enum {
20 break ident.to_string();
21 }
22 }
23 } else {
24 panic!("Could not find type name");
25 }
26 };
27
28 let output = format!(
29 "#[automatically_derived] impl ::riptc_bridge::Riptc for {} {{}}",
30 type_name
31 );
32
33 output.parse().unwrap()
34}