spdlog_macros/
lib.rs

1//! Macros implementation of crate [`spdlog-rs`].
2//!
3//! `spdlog-macros` should currently not be used as a standalone dependency, use
4//! [`spdlog-rs`] instead.
5//!
6//! [`spdlog-rs`]: https://crates.io/crates/spdlog-rs
7
8mod pattern;
9
10use proc_macro::TokenStream;
11use proc_macro2::TokenStream as TokenStream2;
12use spdlog_internal::pattern_parser::Result;
13
14#[proc_macro]
15pub fn pattern(input: TokenStream) -> TokenStream {
16    let pattern = syn::parse_macro_input!(input);
17    into_or_error(pattern::pattern_impl(pattern))
18}
19
20#[proc_macro]
21pub fn runtime_pattern(input: TokenStream) -> TokenStream {
22    // We must make this macro a procedural macro because macro cannot match the "$"
23    // token which is used in the custom patterns.
24
25    let runtime_pattern = syn::parse_macro_input!(input);
26    into_or_error(pattern::runtime_pattern_impl(runtime_pattern))
27}
28
29fn into_or_error(result: Result<TokenStream2>) -> TokenStream {
30    match result {
31        Ok(stream) => stream.into(),
32        Err(err) => panic!("{}", err),
33    }
34}