Macro lazy_regex::regex_if

source ·
regex_if!() { /* proc-macro */ }
Expand description

Return an Option, with T being the type returned by the block or expression given as third argument.

If the regex matches, executes the expression and return it as Some. Return None if the regex doesn’t match.

 let grey = regex_if!(r#"^gr(a|e)y\((?<level>\d{1,2})\)$"#, "grey(22)", {
     level.parse().unwrap()
 });
 assert_eq!(grey, Some(22));