#[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

The maximum pattern ID value, represented as a usize.

The total number of patterns that are allowed in any single regex engine.

The zero pattern ID value.

The number of bytes that a single PatternID uses in memory.

Create a new pattern ID.

If the given identifier exceeds PatternID::MAX, then this returns an error.

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.

Like PatternID::new, but panics if the given ID is not valid.

Return this pattern ID as a usize.

Return the internal u32 of this pattern ID.

Return the internal u32 of this pattern ID represented as an i32.

This is guaranteed to never overflow an i32.

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

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.

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.

Return the underlying pattern ID integer as raw bytes in native endian format.

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

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

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

The returned type after indexing.

Performs the indexing (container[index]) operation. Read more

The returned type after indexing.

Performs the indexing (container[index]) operation. Read more

Performs the mutable indexing (container[index]) operation. Read more

Performs the mutable indexing (container[index]) operation. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. 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.

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.

The type returned in the event of a conversion error.

Performs the conversion.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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.