pub use regex::Regex;
#[doc(hidden)]
pub mod import {
pub use core::marker::PhantomData;
pub use std::sync::LazyLock;
}
pub type StaticRegex = &'static Regex;
pub trait TypeRegex {
#[must_use]
fn get() -> StaticRegex;
}
pub const INVALID: &str = "invalid regex";
#[macro_export]
macro_rules! type_regex {
($vis: vis $name: ident = $regex: expr $(=> $doc: expr)?) => {
$(
#[doc = $doc]
)?
$vis struct $name {
private: $crate::types::import::PhantomData<()>,
}
impl $crate::types::TypeRegex for $name {
fn get() -> $crate::types::StaticRegex {
use $crate::types::import::LazyLock;
static REGEX: LazyLock<$crate::types::Regex> = LazyLock::new(|| {
$crate::types::Regex::new($regex).expect($crate::types::INVALID)
});
LazyLock::force(®EX)
}
}
};
}