regex_automata::util::look

Struct LookSet

Source
pub struct LookSet {
    pub bits: u32,
}
Expand description

LookSet is a memory-efficient set of look-around assertions.

This is useful for efficiently tracking look-around assertions. For example, a thompson::NFA provides properties that return LookSets.

Fields§

§bits: u32

The underlying representation this set is exposed to make it possible to store it somewhere efficiently. The representation is that of a bitset, where each assertion occupies bit i where i = Look::as_repr().

Note that users of this internal representation must permit the full range of u16 values to be represented. For example, even if the current implementation only makes use of the 10 least significant bits, it may use more bits in a future semver compatible release.

Implementations§

Source§

impl LookSet

Source

pub fn empty() -> LookSet

Create an empty set of look-around assertions.

Source

pub fn full() -> LookSet

Create a full set of look-around assertions.

This set contains all possible look-around assertions.

Source

pub fn singleton(look: Look) -> LookSet

Create a look-around set containing the look-around assertion given.

This is a convenience routine for creating an empty set and inserting one look-around assertions.

Source

pub fn len(self) -> usize

Returns the total number of look-around assertions in this set.

Source

pub fn is_empty(self) -> bool

Returns true if and only if this set is empty.

Source

pub fn contains(self, look: Look) -> bool

Returns true if and only if the given look-around assertion is in this set.

Source

pub fn contains_anchor(&self) -> bool

Returns true if and only if this set contains any anchor assertions. This includes both “start/end of haystack” and “start/end of line.”

Source

pub fn contains_anchor_haystack(&self) -> bool

Returns true if and only if this set contains any “start/end of haystack” anchors. This doesn’t include “start/end of line” anchors.

Source

pub fn contains_anchor_line(&self) -> bool

Returns true if and only if this set contains any “start/end of line” anchors. This doesn’t include “start/end of haystack” anchors. This includes both \n line anchors and CRLF (\r\n) aware line anchors.

Source

pub fn contains_anchor_lf(&self) -> bool

Returns true if and only if this set contains any “start/end of line” anchors that only treat \n as line terminators. This does not include haystack anchors or CRLF aware line anchors.

Source

pub fn contains_anchor_crlf(&self) -> bool

Returns true if and only if this set contains any “start/end of line” anchors that are CRLF-aware. This doesn’t include “start/end of haystack” or “start/end of line-feed” anchors.

Source

pub fn contains_word(self) -> bool

Returns true if and only if this set contains any word boundary or negated word boundary assertions. This include both Unicode and ASCII word boundaries.

Source

pub fn contains_word_unicode(self) -> bool

Returns true if and only if this set contains any Unicode word boundary or negated Unicode word boundary assertions.

Source

pub fn contains_word_ascii(self) -> bool

Returns true if and only if this set contains any ASCII word boundary or negated ASCII word boundary assertions.

Source

pub fn iter(self) -> LookSetIter

Returns an iterator over all of the look-around assertions in this set.

Source

pub fn insert(self, look: Look) -> LookSet

Return a new set that is equivalent to the original, but with the given assertion added to it. If the assertion is already in the set, then the returned set is equivalent to the original.

Source

pub fn set_insert(&mut self, look: Look)

Updates this set in place with the result of inserting the given assertion into this set.

Source

pub fn remove(self, look: Look) -> LookSet

Return a new set that is equivalent to the original, but with the given assertion removed from it. If the assertion is not in the set, then the returned set is equivalent to the original.

Source

pub fn set_remove(&mut self, look: Look)

Updates this set in place with the result of removing the given assertion from this set.

Source

pub fn subtract(self, other: LookSet) -> LookSet

Returns a new set that is the result of subtracting the given set from this set.

Source

pub fn set_subtract(&mut self, other: LookSet)

Updates this set in place with the result of subtracting the given set from this set.

Source

pub fn union(self, other: LookSet) -> LookSet

Returns a new set that is the union of this and the one given.

Source

pub fn set_union(&mut self, other: LookSet)

Updates this set in place with the result of unioning it with the one given.

Source

pub fn intersect(self, other: LookSet) -> LookSet

Returns a new set that is the intersection of this and the one given.

Source

pub fn set_intersect(&mut self, other: LookSet)

Updates this set in place with the result of intersecting it with the one given.

Source

pub fn read_repr(slice: &[u8]) -> LookSet

Return a LookSet from the slice given as a native endian 32-bit integer.

§Panics

This panics if slice.len() < 4.

Source

pub fn write_repr(self, slice: &mut [u8])

Write a LookSet as a native endian 32-bit integer to the beginning of the slice given.

§Panics

This panics if slice.len() < 4.

Source

pub fn available(self) -> Result<(), UnicodeWordBoundaryError>

Checks that all assertions in this set can be matched.

Some assertions, such as Unicode word boundaries, require optional (but enabled by default) tables that may not be available. If there are assertions in this set that require tables that are not available, then this will return an error.

Specifically, this returns an error when the the unicode-word-boundary feature is not enabled and this set contains a Unicode word boundary assertion.

It can be useful to use this on the result of NFA::look_set_any when building a matcher engine to ensure methods like LookMatcher::matches_set do not panic at search time.

Trait Implementations§

Source§

impl Clone for LookSet

Source§

fn clone(&self) -> LookSet

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 LookSet

Source§

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

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

impl Default for LookSet

Source§

fn default() -> LookSet

Returns the “default value” for a type. Read more
Source§

impl PartialEq for LookSet

Source§

fn eq(&self, other: &LookSet) -> 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 Copy for LookSet

Source§

impl Eq for LookSet

Source§

impl StructuralPartialEq for LookSet

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.