Trait regex::re_trait::RegularExpression[][src]

pub trait RegularExpression: Sized {
    type Text: ?Sized;
    fn slots_len(&self) -> usize;
fn next_after_empty(&self, text: &Self::Text, i: usize) -> usize;
fn shortest_match_at(
        &self,
        text: &Self::Text,
        start: usize
    ) -> Option<usize>;
fn is_match_at(&self, text: &Self::Text, start: usize) -> bool;
fn find_at(&self, text: &Self::Text, start: usize) -> Option<(usize, usize)>;
fn read_captures_at(
        &self,
        locs: &mut Locations,
        text: &Self::Text,
        start: usize
    ) -> Option<(usize, usize)>; fn locations(&self) -> Locations { ... }
fn find_iter(self, text: &Self::Text) -> Matches<Self> { ... }
fn captures_iter(self, text: &Self::Text) -> CaptureMatches<Self> { ... } }

RegularExpression describes types that can implement regex searching.

This trait is my attempt at reducing code duplication and to standardize the internal API. Specific duplication that is avoided are the find and capture iterators, which are slightly tricky.

It's not clear whether this trait is worth it, and it also isn't clear whether it's useful as a public trait or not. Methods like next_after_empty reak of bad design, but the rest of the methods seem somewhat reasonable. One particular thing this trait would expose would be the ability to start the search of a regex anywhere in a haystack, which isn't possible in the current public API.

Associated Types

The type of the haystack.

Required Methods

The number of capture slots in the compiled regular expression. This is always two times the number of capture groups (two slots per group).

Returns the position of the next character after i.

For example, a haystack with type &[u8] probably returns i+1, whereas a haystack with type &str probably returns i plus the length of the next UTF-8 sequence.

Returns the location of the shortest match.

Returns whether the regex matches the text given.

Returns the leftmost-first match location if one exists.

Returns the leftmost-first match location if one exists, and also fills in any matching capture slot locations.

Provided Methods

Allocates fresh space for all capturing groups in this regex.

Important traits for Matches<'t, R>

Returns an iterator over all non-overlapping successive leftmost-first matches.

Important traits for CaptureMatches<'t, R>

Returns an iterator over all non-overlapping successive leftmost-first matches with captures.

Implementors