gitarena_macros/
lib.rs

1use proc_macro::TokenStream;
2use proc_macro_error::proc_macro_error;
3
4use config::from_config as internal_from_config;
5use config::from_optional_config as internal_from_optional_config;
6use route::route as internal_route;
7
8mod config;
9mod route;
10
11/// Creates resource handler, allowing multiple HTTP method guards.
12/// This method is similar to the actix_web method `actix_web::route`
13///
14/// # Syntax
15///
16/// ```text
17/// #[route("path", method = "HTTP_METHOD"[, attributes])]
18/// ```
19///
20/// # Attributes
21///
22/// - `"path"` - Raw literal string with path for which to register handler.
23/// - `method="HTTP_METHOD"` - Registers HTTP method to provide guard for. Upper-case string, "GET", "POST" for example.
24/// - `guard="function_name"` - Registers function as guard using `actix_web::guard::fn_guard`
25/// - `wrap="Middleware"` - Registers a resource middleware.
26///
27/// # Differences
28///
29/// 1. This macro requires `anyhow::Result` as a return type while the actix macro requires `actix_web::Result`
30/// 2. This macro attaches `#[instrument(skip_all)]` from the tracing library to the function with the correct method name
31///
32#[proc_macro_attribute]
33#[proc_macro_error]
34pub fn route(args: TokenStream, input: TokenStream) -> TokenStream {
35    internal_route(args, input)
36}
37
38#[proc_macro]
39pub fn from_config(input: TokenStream) -> TokenStream {
40    internal_from_config(input)
41}
42
43#[proc_macro]
44pub fn from_optional_config(input: TokenStream) -> TokenStream {
45    internal_from_optional_config(input)
46}