riptc_bridge_macros/lib.rs
1use proc_macro::TokenStream;
2
3/// Indicates to riptc that a type should be generated and shared despite not being
4/// a direct dependency of a route that we have detected.
5///
6/// This macro in and of itself doesn't do anything, it simply regurgitates your code back out.
7#[proc_macro_derive(Riptc)]
8pub fn riptc_marker(input: TokenStream) -> TokenStream {
9 // we just do this by hand here because we are simply implementing a marker
10 // trait and we don't want to bring in syn / quote for no reason and bloat compile times
11 let type_name = input
12 .into_iter()
13 .find_map(|token| {
14 if let proc_macro::TokenTree::Ident(ident) = token {
15 Some(ident.to_string())
16 } else {
17 None
18 }
19 })
20 .expect("no type name");
21
22 let output = format!(
23 "#[automatically_derived] impl ::riptc_bridge::Riptc for {} {{}}",
24 type_name
25 );
26
27 output.parse().unwrap()
28}