telegram_bot2_macros/
bot_main.rs

1use proc_macro::{Span, TokenStream};
2use proc_macro_error::abort;
3use quote::ToTokens;
4use syn::Item;
5
6pub fn try_bot_main(_attr: TokenStream, item: TokenStream) -> Result<TokenStream, ()> {
7    let item = if let Item::Fn(f) = syn::parse::<Item>(item).map_err(|_| abort!(Span::call_site(), "Could not parse"))? {
8        f
9    } else {
10        abort!(Span::call_site(), "Can only be applied to functions")
11    };
12
13    Ok(format!(
14        r#"
15        #[tokio::main]
16        async fn main(){{
17            {}.launch().await;
18        }}
19        "#,
20        item.block.to_token_stream()
21    )
22    .parse()
23    .unwrap())
24}