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 match &token {
16 proc_macro::TokenTree::Ident(ident) => {
17 let ident_str = ident.to_string();
18 if ident_str == "struct" || ident_str == "enum" {
19 found_struct_or_enum = true;
20 } else if found_struct_or_enum {
21 break ident.to_string();
22 }
23 }
24 _ => {}
25 }
26 } else {
27 panic!("Could not find type name");
28 }
29 };
30
31 let output = format!(
32 "#[automatically_derived] impl ::riptc_bridge::Riptc for {} {{}}",
33 type_name
34 );
35
36 output.parse().unwrap()
37}