Skip to main content

telegram_macros/
lib.rs

1//! Procedural macros for `telegram-rs`.
2//!
3//! Provides attribute macros for declarative bot creation and command routing.
4
5use proc_macro::TokenStream;
6use quote::quote;
7use syn::parse_macro_input;
8
9/// Attribute macro for decorating bot entrypoints and definitions.
10///
11/// Reserved for high-level declarative bot runtime setups.
12///
13/// # Examples
14///
15/// ```ignore
16/// #[telegram_rs_2::bot]
17/// async fn my_bot() {
18///     // Bot setup
19/// }
20/// ```
21#[proc_macro_attribute]
22pub fn bot(_args: TokenStream, item: TokenStream) -> TokenStream {
23    item
24}
25
26/// Attribute macro for declaring Telegram bot command handler functions.
27///
28/// Wraps a command handler function, enabling automated routing and metadata extraction.
29///
30/// # Examples
31///
32/// ```ignore
33/// #[telegram_rs_2::command("/start")]
34/// async fn handle_start(bot: Bot, msg: Message) {
35///     // Handle /start
36/// }
37/// ```
38#[proc_macro_attribute]
39pub fn command(_args: TokenStream, item: TokenStream) -> TokenStream {
40    let input = parse_macro_input!(item as syn::ItemFn);
41
42    let expanded = quote! {
43        #input
44    };
45
46    TokenStream::from(expanded)
47}