pub struct PatternID(/* private fields */);
Expand description
The identifier of a regex pattern, represented by a SmallIndex
.
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.
See the SmallIndex
type for more information about what it means for
a pattern ID to be a “small index.”
Note that this type is defined in the
util::primitives
module, but it is also
re-exported at the crate root due to how common it is.
Implementations§
Source§impl PatternID
impl PatternID
Sourcepub const LIMIT: usize = 2_147_483_647usize
pub const LIMIT: usize = 2_147_483_647usize
The total number of values that can be represented.
Sourcepub fn new(value: usize) -> Result<PatternID, PatternIDError>
pub fn new(value: usize) -> Result<PatternID, PatternIDError>
Create a new value that is represented by a “small index.”
If the given index exceeds the maximum allowed value, then this returns an error.
Sourcepub const fn new_unchecked(value: usize) -> PatternID
pub const fn new_unchecked(value: usize) -> PatternID
Create a new value without checking whether the given argument exceeds the maximum.
Using this routine with an invalid value will result in unspecified behavior, but not undefined behavior. In particular, an invalid ID value is likely to cause panics or possibly even silent logical errors.
Callers must never rely on this type to be within a certain range for memory safety.
Sourcepub const fn as_usize(&self) -> usize
pub const fn as_usize(&self) -> usize
Return the internal value as a usize
. This is guaranteed to
never overflow usize
.
Sourcepub const fn as_u64(&self) -> u64
pub const fn as_u64(&self) -> u64
Return the internal value as a u64
. This is guaranteed to
never overflow.
Sourcepub const fn as_u32(&self) -> u32
pub const fn as_u32(&self) -> u32
Return the internal value as a u32
. This is guaranteed to
never overflow u32
.
Sourcepub const fn as_i32(&self) -> i32
pub const fn as_i32(&self) -> i32
Return the internal value as a 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 value as a usize.
Since values represented by a “small index” have constraints
on their maximum value, adding 1
to it will always fit in a
usize
, u32
and a i32
.
Sourcepub fn from_ne_bytes(bytes: [u8; 4]) -> Result<PatternID, PatternIDError>
pub fn from_ne_bytes(bytes: [u8; 4]) -> Result<PatternID, PatternIDError>
Decode this value from the bytes given using the native endian byte order for the current target.
If the decoded integer is not representable as a small index 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 value from the bytes given using the native endian byte order for the current target.
This is analogous to new_unchecked
in that is does not check
whether the decoded integer is representable as a small index.
Sourcepub fn to_ne_bytes(&self) -> [u8; 4]
pub fn to_ne_bytes(&self) -> [u8; 4]
Return the underlying integer as raw bytes in native endian format.