Struct regex_automata::PatternID
source · [−]#[repr(transparent)]pub struct PatternID(_);
Expand description
An identifier for a regex pattern.
The identifier for a pattern corresponds to its relative position among other patterns in a single finite state machine. Namely, when building a multi-pattern regex engine, one must supply a sequence of patterns to match. The position (starting at 0) of each pattern in that sequence represents its identifier. This identifier is in turn used to identify and report matches of that pattern in various APIs.
A pattern ID is guaranteed to be representable by a usize
. Similarly,
the number of patterns in any regex engine in this crate is guaranteed to
be representable by a usize
. This applies to regex engines that have
been deserialized; a deserialization error will be returned if it contains
pattern IDs that violate these requirements in your current environment.
For extra convenience in some cases, this type also guarantees that all
IDs can fit into an i32
and an isize
without overflowing.
Representation
This type is always represented internally by a u32
and is marked as
repr(transparent)
. Thus, this type always has the same representation as
a u32
.
Indexing
For convenience, callers may use a PatternID
to index slices.
Safety
While a PatternID
is meant to guarantee that its value fits into usize
(while using a possibly smaller representation than usize
on some
targets), callers must not rely on this property for safety. Callers may
choose to rely on this property for correctness however.
Implementations
sourceimpl PatternID
impl PatternID
sourcepub const LIMIT: usize
pub const LIMIT: usize
The total number of patterns that are allowed in any single regex engine.
sourcepub fn new(id: usize) -> Result<PatternID, PatternIDError>
pub fn new(id: usize) -> Result<PatternID, PatternIDError>
Create a new pattern ID.
If the given identifier exceeds PatternID::MAX
, then this returns
an error.
sourcepub const fn new_unchecked(id: usize) -> PatternID
pub const fn new_unchecked(id: usize) -> PatternID
Create a new pattern ID without checking whether the given value
exceeds PatternID::MAX
.
While this is unchecked, providing an incorrect value must never sacrifice memory safety, as documented above.
sourcepub fn must(id: usize) -> PatternID
pub fn must(id: usize) -> PatternID
Like PatternID::new
, but panics if the given ID is not valid.
sourcepub const fn as_i32(&self) -> i32
pub const fn as_i32(&self) -> i32
Return the internal u32 of this pattern ID represented as an i32.
This is guaranteed to never overflow an i32
.
sourcepub fn one_more(&self) -> usize
pub fn one_more(&self) -> usize
Returns one more than this pattern ID as a usize.
Since a pattern ID has constraints on its maximum value, adding 1
to
it will always fit in a usize
(and a u32
).
sourcepub fn from_ne_bytes(bytes: [u8; 4]) -> Result<PatternID, PatternIDError>
pub fn from_ne_bytes(bytes: [u8; 4]) -> Result<PatternID, PatternIDError>
Decode this pattern ID from the bytes given using the native endian byte order for the current target.
If the decoded integer is not representable as a pattern ID for the current target, then this returns an error.
sourcepub fn from_ne_bytes_unchecked(bytes: [u8; 4]) -> PatternID
pub fn from_ne_bytes_unchecked(bytes: [u8; 4]) -> PatternID
Decode this pattern ID from the bytes given using the native endian byte order for the current target.
This is analogous to PatternID::new_unchecked
in that is does not
check whether the decoded integer is representable as a pattern ID.
sourcepub fn to_ne_bytes(&self) -> [u8; 4]
pub fn to_ne_bytes(&self) -> [u8; 4]
Return the underlying pattern ID integer as raw bytes in native endian format.
Trait Implementations
sourceimpl Ord for PatternID
impl Ord for PatternID
sourceimpl PartialOrd<PatternID> for PatternID
impl PartialOrd<PatternID> for PatternID
sourcefn partial_cmp(&self, other: &PatternID) -> Option<Ordering>
fn partial_cmp(&self, other: &PatternID) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl TryFrom<u8> for PatternID
impl TryFrom<u8> for PatternID
type Error = Infallible
type Error = Infallible
The type returned in the event of a conversion error.
impl Copy for PatternID
impl Eq for PatternID
impl StructuralEq for PatternID
impl StructuralPartialEq for PatternID
Auto Trait Implementations
impl RefUnwindSafe for PatternID
impl Send for PatternID
impl Sync for PatternID
impl Unpin for PatternID
impl UnwindSafe for PatternID
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more