Macro newstr::regex_is_valid [−][src]
macro_rules! regex_is_valid { ($regex:expr) => { ... }; ($regex:expr, $fn_name:ident) => { ... }; }
Expand description
This macro takes a string that contains a regular expression will construct a new validity
predicate that may be used by the is_valid_newstring
macro.
An optional second parameter provides a name for the new predicate function, overriding the
default is_valid
.
The generated function uses lazy_static
to only compile the regular expression once. You
will require a dependency on both the lazy_static
and regex
crates, as you see in the
example below.
Example
use lazy_static::lazy_static; use regex::Regex; use std::str::FromStr; regex_is_valid!(r"[0-9]+", is_valid_integer);