regex_automata

Struct PatternSet

Source
pub struct PatternSet { /* private fields */ }
Available on crate feature alloc only.
Expand description

A set of PatternIDs.

A set of pattern identifiers is useful for recording which patterns have matched a particular haystack. A pattern set only includes pattern identifiers. It does not include offset information.

§Example

This shows basic usage of a set.

use regex_automata::{PatternID, PatternSet};

let pid1 = PatternID::must(5);
let pid2 = PatternID::must(8);
// Create a new empty set.
let mut set = PatternSet::new(10);
// Insert pattern IDs.
set.insert(pid1);
set.insert(pid2);
// Test membership.
assert!(set.contains(pid1));
assert!(set.contains(pid2));
// Get all members.
assert_eq!(
    vec![5, 8],
    set.iter().map(|p| p.as_usize()).collect::<Vec<usize>>(),
);
// Clear the set.
set.clear();
// Test that it is indeed empty.
assert!(set.is_empty());

Implementations§

Source§

impl PatternSet

Source

pub fn new(capacity: usize) -> PatternSet

Create a new set of pattern identifiers with the given capacity.

The given capacity typically corresponds to (at least) the number of patterns in a compiled regex object.

§Panics

This panics if the given capacity exceeds PatternID::LIMIT. This is impossible if you use the pattern_len() method as defined on any of the regex engines in this crate. Namely, a regex will fail to build by returning an error if the number of patterns given to it exceeds the limit. Therefore, the number of patterns in a valid regex is always a correct capacity to provide here.

Source

pub fn clear(&mut self)

Clear this set such that it contains no pattern IDs.

Source

pub fn contains(&self, pid: PatternID) -> bool

Return true if and only if the given pattern identifier is in this set.

Source

pub fn insert(&mut self, pid: PatternID) -> bool

Insert the given pattern identifier into this set and return true if the given pattern ID was not previously in this set.

If the pattern identifier is already in this set, then this is a no-op.

Use PatternSet::try_insert for a fallible version of this routine.

§Panics

This panics if this pattern set has insufficient capacity to store the given pattern ID.

Source

pub fn try_insert( &mut self, pid: PatternID, ) -> Result<bool, PatternSetInsertError>

Insert the given pattern identifier into this set and return true if the given pattern ID was not previously in this set.

If the pattern identifier is already in this set, then this is a no-op.

§Errors

This returns an error if this pattern set has insufficient capacity to store the given pattern ID.

Source

pub fn is_empty(&self) -> bool

Return true if and only if this set has no pattern identifiers in it.

Source

pub fn is_full(&self) -> bool

Return true if and only if this set has the maximum number of pattern identifiers in the set. This occurs precisely when PatternSet::len() == PatternSet::capacity().

This particular property is useful to test because it may allow one to stop a search earlier than you might otherwise. Namely, if a search is only reporting which patterns match a haystack and if you know all of the patterns match at a given point, then there’s no new information that can be learned by continuing the search. (Because a pattern set does not keep track of offset information.)

Source

pub fn len(&self) -> usize

Returns the total number of pattern identifiers in this set.

Source

pub fn capacity(&self) -> usize

Returns the total number of pattern identifiers that may be stored in this set.

This is guaranteed to be less than or equal to PatternID::LIMIT.

Typically, the capacity of a pattern set matches the number of patterns in a regex object with which you are searching.

Source

pub fn iter(&self) -> PatternSetIter<'_>

Returns an iterator over all pattern identifiers in this set.

The iterator yields pattern identifiers in ascending order, starting at zero.

Trait Implementations§

Source§

impl Clone for PatternSet

Source§

fn clone(&self) -> PatternSet

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 PatternSet

Source§

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

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

impl PartialEq for PatternSet

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for PatternSet

Source§

impl StructuralPartialEq for PatternSet

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where 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 T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.