Struct PatternSet
pub struct PatternSet { /* private fields */ }
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 ;
let pid1 = must;
let pid2 = must;
// Create a new empty set.
let mut set = new;
// Insert pattern IDs.
set.insert;
set.insert;
// Test membership.
assert!;
assert!;
// Get all members.
assert_eq!;
// Clear the set.
set.clear;
// Test that it is indeed empty.
assert!;
Implementations
impl PatternSet
fn new(capacity: usize) -> PatternSetCreate 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 thepattern_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.fn clear(&mut self)Clear this set such that it contains no pattern IDs.
fn contains(&self, pid: PatternID) -> boolReturn true if and only if the given pattern identifier is in this set.
fn insert(&mut self, pid: PatternID) -> boolInsert the given pattern identifier into this set and return
trueif 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_insertfor a fallible version of this routine.Panics
This panics if this pattern set has insufficient capacity to store the given pattern ID.
fn try_insert(&mut self, pid: PatternID) -> Result<bool, PatternSetInsertError>Insert the given pattern identifier into this set and return
trueif 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.
fn is_empty(&self) -> boolReturn true if and only if this set has no pattern identifiers in it.
fn is_full(&self) -> boolReturn 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.)
fn len(&self) -> usizeReturns the total number of pattern identifiers in this set.
fn capacity(&self) -> usizeReturns 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.
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
impl Clone for PatternSet
fn clone(&self) -> Self
impl Debug for PatternSet
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Eq for PatternSet
impl PartialEq for PatternSet
fn eq(&self, other: &Self) -> bool
impl StructuralPartialEq for PatternSet
Auto Trait Implementations
impl Freeze for PatternSet
impl RefUnwindSafe for PatternSet
impl Send for PatternSet
impl Sync for PatternSet
impl Unpin for PatternSet
impl UnsafeUnpin for PatternSet
impl UnwindSafe for PatternSet
Blanket Implementations
impl<T> Any for PatternSet
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for PatternSet
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for PatternSet
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for PatternSet
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for PatternSet
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for PatternSet
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T, U> Into<U> for PatternSet
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for PatternSet
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for PatternSet
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>