Struct regex_test::Captures

source ·
pub struct Captures { /* private fields */ }
Expand description

Captures represents a single group of captured matches from a regex search.

There is always at least 1 group, and the first group is always present and corresponds to the overall match.

Implementations§

source§

impl Captures

source

pub fn new<I: IntoIterator<Item = Option<Span>>>( id: usize, it: I ) -> Result<Captures>

Create a new set of captures for a single match of a regex.

If available, iterator should provide items for every capturing group in the regex, including the 0th capturing group corresponding to the entire match. At minimum, the 0th capturing group should be provided.

If a capturing group did not participate in the match, then a None value should be used. (The 0th capturing group should never be None.)

If the iterator yields no elements or the first group is None, then this returns an error.

The id should be the ID of the pattern that matched. This is always 0 for single-pattern regexes. Otherwise, the ID of a pattern starts at 0 and is incremented by 1 for each subsequent pattern.

Note that there are possibly more convenient and infallible From impls for converting a Match or a Span into a Captures.

source

pub fn id(&self) -> usize

Returns the ID of the pattern that matched.

For any single pattern regexes, this should always be zero.

source

pub fn groups(&self) -> &[Option<Span>]

Returns a slice of the underlying spans, each group corresponding to the (possibly) matched span. The first group in the slice returned is guaranteed to correspond to the overall match span and is thus non-None. All other groups may be None. Similarly, the slice is guaranteed to have length at least 1.

source

pub fn len(&self) -> usize

Returns the number of groups (including the first) in these captures.

The length returned is guaranteed to be greater than zero.

source

pub fn to_match(&self) -> Match

Returns the overall match, including the pattern ID, for this group of captures.

source

pub fn to_span(&self) -> Span

Returns the overall match span for this group of captures.

Trait Implementations§

source§

impl Clone for Captures

source§

fn clone(&self) -> Captures

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Captures

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for Captures

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl From<Match> for Captures

Converts a plain Match to a Captures value, where the match corresponds to the first and only group in Captures.

source§

fn from(m: Match) -> Captures

Converts to this type from the input type.
source§

impl From<Span> for Captures

Converts a plain Span to a Captures value, where the span corresponds to the first and only group in Captures. Since a Span does not contain a pattern ID, the pattern ID used in this conversion is always 0.

source§

fn from(sp: Span) -> Captures

Converts to this type from the input type.
source§

impl PartialEq<Captures> for Captures

source§

fn eq(&self, other: &Captures) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Captures

source§

impl StructuralEq for Captures

source§

impl StructuralPartialEq for Captures

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,