pub trait Regex<I, const N: usize>: Debugwhere
I: HaystackItem,{
type Pattern: Matcher<I>;
type Capture<'a, H: Haystack<'a>>: CaptureFromRanges<'a, H, N>
where I: 'a;
// Provided methods
fn is_match<'a, H>(hay: impl IntoHaystack<'a, H>) -> bool
where H: HaystackOf<'a, I> { ... }
fn contains_match<'a, H>(hay: impl IntoHaystack<'a, H>) -> bool
where H: HaystackOf<'a, I> { ... }
fn slice_matching<'a, H>(
hay: impl IntoHaystack<'a, H>,
) -> Option<<H as HaystackIter<'a>>::Slice>
where H: HaystackOf<'a, I> { ... }
fn slice_all_matching<'a, H>(
hay: impl IntoHaystack<'a, H>,
overlapping: bool,
) -> Vec<<H as HaystackIter<'a>>::Slice>
where H: HaystackOf<'a, I> { ... }
fn do_capture<'a, H>(
hay: impl IntoHaystack<'a, H>,
) -> Option<Self::Capture<'a, H>>
where H: HaystackOf<'a, I> { ... }
fn find_capture<'a, H>(
hay: impl IntoHaystack<'a, H>,
) -> Option<Self::Capture<'a, H>>
where H: HaystackOf<'a, I> { ... }
fn find_all_captures<'a, H>(
hay: impl IntoHaystack<'a, H>,
overlapping: bool,
) -> Vec<Self::Capture<'a, H>>
where H: HaystackOf<'a, I> { ... }
}Expand description
A trait that is automatically implemented for types produced by the regex! macro. Various
function are included that test this pattern against a provided Haystack.
Altough rarely encountered, this trait’s generic parameter, I refers to the item that can be
matched individually from the provided I::Slice. This is used so that the same expression can
be used to match various haystack types, including &str (I = char) and &[u8] (I = u8).
Implementations for both of these slice/item pairs will be implemented by the macro.
Required Associated Types§
type Pattern: Matcher<I>
type Capture<'a, H: Haystack<'a>>: CaptureFromRanges<'a, H, N> where I: 'a
Provided Methods§
Sourcefn is_match<'a, H>(hay: impl IntoHaystack<'a, H>) -> boolwhere
H: HaystackOf<'a, I>,
fn is_match<'a, H>(hay: impl IntoHaystack<'a, H>) -> boolwhere
H: HaystackOf<'a, I>,
Returns true if this Regex matches the entire haystack provided. This should probably
be the default matching function to use.
A similar behavior can be achieved by using start and end anchors in an expression and then
calling contains_match. This function should be prefered however,
because it fails fast if the first character doesn’t match.
To check if this Regex matches and perform capturing, use do_capture
instead.
Sourcefn contains_match<'a, H>(hay: impl IntoHaystack<'a, H>) -> boolwhere
H: HaystackOf<'a, I>,
fn contains_match<'a, H>(hay: impl IntoHaystack<'a, H>) -> boolwhere
H: HaystackOf<'a, I>,
Returns true if this Regex matches any substring of the haystack provided. To retrieve the
actual substring itself, use slice_matching or
find_capture.
Anchors can be used as a part of this Regex to perform more complex behaviors, but if you’re
just wrapping an expression with ^ and $, see is_match instead.
Sourcefn slice_matching<'a, H>(
hay: impl IntoHaystack<'a, H>,
) -> Option<<H as HaystackIter<'a>>::Slice>where
H: HaystackOf<'a, I>,
fn slice_matching<'a, H>(
hay: impl IntoHaystack<'a, H>,
) -> Option<<H as HaystackIter<'a>>::Slice>where
H: HaystackOf<'a, I>,
Returns the slice that matches this Regex first. This is the slicing variant of
contains_match.
This function runs through the Regex first and then the haystack. This has a slight semantic difference in some scenarios.
Note that there is no slicing equivalent of is_match, because any match
has to be the entire haystack.
Sourcefn slice_all_matching<'a, H>(
hay: impl IntoHaystack<'a, H>,
overlapping: bool,
) -> Vec<<H as HaystackIter<'a>>::Slice>where
H: HaystackOf<'a, I>,
fn slice_all_matching<'a, H>(
hay: impl IntoHaystack<'a, H>,
overlapping: bool,
) -> Vec<<H as HaystackIter<'a>>::Slice>where
H: HaystackOf<'a, I>,
Returns all slices of the provided haystack that match this Regex, optionally overlapping.
This is the only match function that returns more than one result.
Sourcefn do_capture<'a, H>(
hay: impl IntoHaystack<'a, H>,
) -> Option<Self::Capture<'a, H>>where
H: HaystackOf<'a, I>,
fn do_capture<'a, H>(
hay: impl IntoHaystack<'a, H>,
) -> Option<Self::Capture<'a, H>>where
H: HaystackOf<'a, I>,
Returns a Self::Capture representing the provided haystack matched against this Regex.
This includes any named or numbered capturing groups in the expression. As with
is_match, this function acts on the entire haystack, and needs to match
every character from start to end.
Provides the same result as find_capture with start and end anchors,
although without needing to check any non-starting substring.
Sourcefn find_capture<'a, H>(
hay: impl IntoHaystack<'a, H>,
) -> Option<Self::Capture<'a, H>>where
H: HaystackOf<'a, I>,
fn find_capture<'a, H>(
hay: impl IntoHaystack<'a, H>,
) -> Option<Self::Capture<'a, H>>where
H: HaystackOf<'a, I>,
Returns the Self::Capture that matches this Regex first, similar to
slice_matching but with any named or numbered groups included.
Anchors should be used for complex behavior, beyond unconditional start and end matches. See
do_capture instead to capture a full haystack.
Sourcefn find_all_captures<'a, H>(
hay: impl IntoHaystack<'a, H>,
overlapping: bool,
) -> Vec<Self::Capture<'a, H>>where
H: HaystackOf<'a, I>,
fn find_all_captures<'a, H>(
hay: impl IntoHaystack<'a, H>,
overlapping: bool,
) -> Vec<Self::Capture<'a, H>>where
H: HaystackOf<'a, I>,
Returns a Self::Capture representing every full match of this Regex in the provided
haystack, similar to slice_all_matching. This can optionally
include overlapping matches.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
Source§impl Regex<char, 5> for Email
Available on crate feature demo only.
impl Regex<char, 5> for Email
demo only.type Pattern = Then<char, CaptureGroup<char, QuantifierNOrMore<char, Or4<char, ScalarRange<'0', '9'>, ScalarRange<'A', 'Z'>, Scalar<'_'>, ScalarRange<'a', 'z'>>, 1>, 1>, Then<char, Scalar<'@'>, CaptureGroup<char, Then<char, CaptureGroup<char, QuantifierNOrMore<char, Or4<char, ScalarRange<'0', '9'>, ScalarRange<'A', 'Z'>, Scalar<'_'>, ScalarRange<'a', 'z'>>, 1>, 3>, QuantifierNToM<char, CaptureGroup<char, Then<char, Scalar<'.'>, QuantifierNOrMore<char, Or4<char, ScalarRange<'0', '9'>, ScalarRange<'A', 'Z'>, Scalar<'_'>, ScalarRange<'a', 'z'>>, 1>>, 4>, 0, 1>>, 2>>>
type Capture<'a, H: Haystack<'a>> = EmailCapture<'a, H>
Source§impl Regex<u8, 5> for Email
Available on crate feature demo only.
impl Regex<u8, 5> for Email
demo only.