powerfmt_macros/
lib.rs

1//! Procedural macros for `powerfmt`.
2//!
3//! This crate is an implementation detail of `powerfmt` and should not be used directly.
4
5#![allow(
6    clippy::missing_const_for_fn, // irrelevant for proc macros
7    clippy::std_instead_of_core, // irrelevant for proc macros
8    clippy::std_instead_of_alloc, // irrelevant for proc macros
9    clippy::alloc_instead_of_core, // irrelevant for proc macros
10)]
11
12/// Macros for `SmartDisplay`.
13mod smart_display {
14    pub(crate) mod delegate;
15    pub(crate) mod private_metadata;
16}
17
18use proc_macro::TokenStream;
19
20/// Declare an attribute macro.
21macro_rules! attribute {
22    ($($mod:ident)::+ => $public:ident) => {
23        #[doc = concat!("The `#[", attribute!(@stringify $($mod)+), "]` attribute.")]
24        #[proc_macro_attribute]
25        pub fn $public(attr: TokenStream, item: TokenStream) -> TokenStream {
26            match $($mod)::+::implementation(attr.into(), item.into()) {
27                Ok(ts) => ts.into(),
28                Err(err) => err.to_compile_error().into(),
29            }
30        }
31    };
32    (@stringify $first:ident $($remaining:ident)*) => {
33        concat!(stringify!($first), $("::", stringify!($remaining),)*)
34    };
35}
36
37attribute!(smart_display::delegate => smart_display_delegate);
38attribute!(smart_display::private_metadata => smart_display_private_metadata);