File tree 5 files changed +27
-0
lines changed
src/formatter/pattern_formatter
5 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,13 @@ pub fn runtime_pattern(input: TokenStream) -> TokenStream {
26
26
into_or_error ( pattern:: runtime_pattern_impl ( runtime_pattern) )
27
27
}
28
28
29
+ #[ proc_macro]
30
+ pub fn runtime_pattern_disabled ( _: TokenStream ) -> TokenStream {
31
+ panic ! (
32
+ "macro `runtime_pattern` required to enable crate feature `runtime-pattern` for spdlog-rs"
33
+ ) ;
34
+ }
35
+
29
36
fn into_or_error ( result : Result < TokenStream2 > ) -> TokenStream {
30
37
match result {
31
38
Ok ( stream) => stream. into ( ) ,
Original file line number Diff line number Diff line change @@ -342,6 +342,10 @@ use crate::{
342
342
/// [`FullFormatter`]: crate::formatter::FullFormatter
343
343
pub use :: spdlog_macros:: pattern;
344
344
345
+ // Emit a compile error if the feature is not enabled.
346
+ #[ cfg( not( feature = "runtime-pattern" ) ) ]
347
+ pub use :: spdlog_macros:: runtime_pattern_disabled as runtime_pattern;
348
+
345
349
/// Formats logs according to a specified pattern.
346
350
#[ derive( Clone ) ]
347
351
pub struct PatternFormatter < P > {
Original file line number Diff line number Diff line change @@ -5,4 +5,6 @@ fn compile_fail() {
5
5
t. compile_fail ( "tests/compile_fail/pattern_macro_*.rs" ) ;
6
6
#[ cfg( feature = "runtime-pattern" ) ]
7
7
t. compile_fail ( "tests/compile_fail/pattern_runtime_macro_*.rs" ) ;
8
+ #[ cfg( not( feature = "runtime-pattern" ) ) ]
9
+ t. compile_fail ( "tests/compile_fail/pattern_runtime_disabled.rs" ) ;
8
10
}
Original file line number Diff line number Diff line change
1
+ use spdlog:: formatter:: runtime_pattern;
2
+
3
+ fn runtime_pattern ( ) {
4
+ runtime_pattern ! ( "{logger}" ) ;
5
+ }
6
+
7
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ error: proc macro panicked
2
+ --> tests/compile_fail/pattern_runtime_disabled.rs:4:5
3
+ |
4
+ 4 | runtime_pattern!("{logger}");
5
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6
+ |
7
+ = help: message: macro `runtime_pattern` required to enable crate feature `runtime-pattern` for spdlog-rs
You can’t perform that action at this time.
0 commit comments