Macro type_regex

Source
macro_rules! type_regex {
    ($vis: vis $name: ident = $regex: expr $(=> $doc: expr)?) => { ... };
}
Available on crate feature regex only.
Expand description

Lifts strings to type-level regular expressions.

use refinement_types::type_regex;

type_regex!(Integer = "^0|[1-9][0-9]*$");

Is equivalent to:

use std::{fmt, marker::PhantomData, sync::LazyLock};

use refinement_types::{Regex, StaticRegex, TypeRegex};

struct Integer {
    private: PhantomData<()>,
}

impl TypeRegex for Integer {
    fn get() -> StaticRegex {
        static REGEX: LazyLock<Regex> = LazyLock::new(|| {
            Regex::new("^0|[1-9][0-9]*$").expect("invalid regex")
        });

        LazyLock::force(&REGEX)
    }
}