Macro wikimedia::lazy_regex

source ·
macro_rules! lazy_regex {
    ( $( $re:expr ),+ ) => { ... };
}
Expand description

Lazily constructs a cached instance of regex::Regex.

On first invocation the string inside the macro is complied to a Regex with Regex::new(re: &str), then returns the same instance on subsequent invocations of the same macro (e.g. if invoked in a loop body or if used in a function that is called multiple times).

Returns a value of type &'static Regex.

The 1 or more arguments given to the macro are concatenated with the slice::concat method before calling Regex::new(re: &str) with the result. All arguments must implement the trait std::borrow::Borrow<str>, which includes &str and String. The reason for this feature is to enable re-use of substrings in different regexes. See the unit tests in this source file for an example.

You must have dependencies on the crates once_cell and regex to use this macro.

Based on this macro in the once_cell crate documentation: https://docs.rs/once_cell/1.17.1/once_cell/index.html#lazily-compiled-regex