aetos_macro/lib.rs
1//! Procedural macros for the aetos metrics library.
2//!
3//! This crate provides the `#[metrics]` attribute macro and `#[derive(Label)]` macro
4//! for generating Prometheus metrics rendering code.
5//!
6//! ## Label Validation
7//!
8//! The `#[metrics]` macro validates that the `label` attribute is not used on common
9//! scalar primitive types (u64, f64, i32, etc.). Using `label` on these types will
10//! produce a compile error:
11//!
12//! ```text
13//! error: the 'label' attribute is not supported on scalar types like u64, f64, etc.
14//! Labels are only supported on collection types that implement IntoIterator.
15//! ```
16//!
17//! **Note:** This validation only catches common primitive types.
18//! Type aliases and custom wrapper types are not detected and will silently ignore labels.
19//!
20//! See the main `aetos` crate documentation for usage examples.
21
22use proc_macro::TokenStream;
23use syn::{DeriveInput, parse_macro_input};
24
25mod label_derive;
26mod metrics_macro;
27
28#[proc_macro_derive(Label)]
29pub fn derive_label(input: TokenStream) -> TokenStream {
30 let input = parse_macro_input!(input as DeriveInput);
31 label_derive::expand_label_derive(input)
32 .unwrap_or_else(|err| err.to_compile_error())
33 .into()
34}
35
36#[proc_macro_attribute]
37pub fn metrics(args: TokenStream, input: TokenStream) -> TokenStream {
38 metrics_macro::expand_metrics_macro(args.into(), input.into())
39 .unwrap_or_else(|err| err.to_compile_error())
40 .into()
41}