runtime_pattern!() { /* proc-macro */ }Expand description
Builds a pattern from a template string at runtime.
It accepts inputs in the form:
ⓘ
// This is not exactly a valid declarative macro, just for intuition.
macro_rules! runtime_pattern {
( $template:expr $(,)? ) => {};
( $template:expr, $( {$$custom:ident} => $ctor:expr ),+ $(,)? ) => {};
}The only difference between runtime_pattern! macro and pattern! macro
is that pattern! macro only accepts a string literal as the pattern
template, while runtime_pattern! macro accepts an expression that can be
evaluated to the pattern template string at runtime.
The returen type of runtime_pattern! macro is
Result<RuntimePattern, spdlog::Error>. An error will be returned when
parsing of the template string fails. If any of the custom patterns given
are invalid, a compilation error will be triggered.
For the input formats and more usages, please refer to pattern! macro.
§Example
use spdlog::formatter::{runtime_pattern, PatternFormatter};
let template = String::from("[{level}] {payload} - {$mypat}{eol}");
let pat = runtime_pattern!(&template, {$mypat} => MyPattern::default)?;
let formatter = PatternFormatter::new(pat);