wtx_macros/
lib.rs

1//! WTX - Macros
2
3#![expect(clippy::too_many_lines, reason = "Unimportant")]
4
5mod client_api_framework;
6mod error;
7mod executor;
8mod from_records;
9mod http;
10mod misc;
11
12use error::Error;
13
14type Result<T> = core::result::Result<T, Error>;
15
16/// API
17///
18/// Creates types referring an API and its possible de-serializers/serializers or transport
19/// variants.
20#[proc_macro_attribute]
21pub fn api(
22  attrs: proc_macro::TokenStream,
23  item: proc_macro::TokenStream,
24) -> proc_macro::TokenStream {
25  match client_api_framework::api::api(attrs, item) {
26    Err(err) => syn::Error::from(err).to_compile_error().into(),
27    Ok(elem) => elem,
28  }
29}
30
31/// Connection Auxiliary
32#[proc_macro_derive(ConnAux)]
33pub fn conn_aux(item: proc_macro::TokenStream) -> proc_macro::TokenStream {
34  match http::conn_aux(item) {
35    Err(err) => syn::Error::from(err).to_compile_error().into(),
36    Ok(elem) => elem,
37  }
38}
39
40/// From records
41#[proc_macro_derive(FromRecords, attributes(from_records))]
42pub fn from_records(item: proc_macro::TokenStream) -> proc_macro::TokenStream {
43  match from_records::from_records(item) {
44    Err(err) => syn::Error::from(err).to_compile_error().into(),
45    Ok(elem) => elem,
46  }
47}
48
49/// Allows the execution of asynchronous programs using the runtime provided by `WTX`.
50#[proc_macro_attribute]
51pub fn main(_: proc_macro::TokenStream, item: proc_macro::TokenStream) -> proc_macro::TokenStream {
52  executor::main(item)
53}
54
55/// Package
56///
57/// A framework-like attribute placed in inline modules that creates all the mandatory elements
58/// and optional elements related to `wtx::pkg::Package`.
59///
60/// ```rust
61/// struct SomeApi;
62///
63/// #[wtx_macros::pkg(data_format(json_rpc("SomeEndpoint")), id(SomeApiId))]
64/// mod pkg {
65///   #[pkg::req_data]
66///   pub struct SomeEndpointReq<'string> {
67///     ping: &'string str,
68///   }
69///
70///   #[pkg::res_data]
71///   pub struct SomeEndpointRes {
72///     pong: String,
73///   }
74/// }
75/// ```
76#[proc_macro_attribute]
77pub fn pkg(
78  attr: proc_macro::TokenStream,
79  item: proc_macro::TokenStream,
80) -> proc_macro::TokenStream {
81  match client_api_framework::pkg::pkg(attr, item) {
82    Err(err) => syn::Error::from(err).to_compile_error().into(),
83    Ok(elem) => elem,
84  }
85}
86
87/// Allows the execution of asynchronous tests using the runtime provided by `WTX`.
88#[proc_macro_attribute]
89pub fn test(_: proc_macro::TokenStream, item: proc_macro::TokenStream) -> proc_macro::TokenStream {
90  executor::test(item)
91}