ct_regex/
demo.rs

1//! A demonstration of the types produced by the `regex!` macro.
2//!
3//! The [`Email`] and [`EmailCapture`] types have both been implemented by the following code:
4//!
5//! ```
6//! regex! {
7//!     pub Email = r"(\w+)@(?<domain>(\w+)(\.\w+)?)"
8//! }
9//! ```
10//!
11//! Notable features include:
12//! - A fully expanded 'matcher' type expression under
13//! [`Email::Pattern`](struct.Email.html#associatedtype.Pattern-1), used to call a set of associated
14//! methods and perform the compile time matching.
15//! - Numbered and named captures generated specfic to the regular expression.
16//!     - Optional and essential captures use [`Option`] as required.
17//! - Lazily sliced capture groups.
18
19use ct_regex_macro::regex;
20
21impl<'a, H: ::ct_regex::internal::haystack::Haystack<'a>>
    ::ct_regex::internal::expr::CaptureFromRanges<'a, H, 5> for
    EmailCapture<'a, H> {
    fn from_ranges(ranges:
            [::std::option::Option<::std::ops::Range<usize>>; 5], hay: H)
        -> ::std::option::Option<Self> {
        let [c0, c1, c2, c3, c4] = ranges;
        ::std::option::Option::Some(Self(hay, c0?, c1?, c2?, c3?, c4,
                ::std::marker::PhantomData))
    }
}regex! {
22    pub Email = r"(\w+)@(?<domain>(\w+)(\.\w+)?)"
23}