const_str/__proc/regex.rs
1pub use const_str_proc_macro::{regex_assert_match, verified_regex};
2
3/// Returns a compile-time verified regex string literal.
4///
5/// # Examples
6///
7/// ```
8/// use regex::Regex;
9/// let re = const_str::verified_regex!(r"^\d{4}-\d{2}-\d{2}$");
10/// assert!(Regex::new(re).is_ok());
11/// ```
12///
13#[cfg_attr(docsrs, doc(cfg(feature = "regex")))]
14#[macro_export]
15macro_rules! verified_regex {
16 ($re: literal) => {
17 $crate::__proc::verified_regex!($re)
18 };
19}
20
21/// Asserts that the string literal matches the pattern.
22///
23/// # Examples
24/// ```
25/// const_str::regex_assert_match!(r"^\d{4}-\d{2}-\d{2}$", "2014-01-01");
26/// ```
27#[cfg_attr(docsrs, doc(cfg(feature = "regex")))]
28#[macro_export]
29macro_rules! regex_assert_match {
30 ($re: literal, $text: literal) => {
31 $crate::__proc::regex_assert_match!($re, $text)
32 };
33}