pub struct PatternSet { /* private fields */ }
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§

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.

Clear this set such that it contains no pattern IDs.

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

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.

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.

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

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.)

Returns the total number of pattern identifiers in this set.

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.

Returns an iterator over all pattern identifiers in this set.

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

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.