Struct PatternID
#[repr(transparent)]
pub struct PatternID(/* private field */);
The identifier of a pattern in an Aho-Corasick automaton.
It is represented by a u32 even on 64-bit systems in order to conserve
space. Namely, on all targets, this type guarantees that its value will
fit in a u32, i32, usize and an isize. This means that on 16-bit
targets, for example, this type's maximum value will never overflow an
isize, which means it will never overflow a i16 even though its
internal representation is still a u32.
Safety
While a PatternID is meant to guarantee that its value fits into usize
without using as much space as a usize on all targets, callers must
not rely on this property for safety. Callers may choose to rely on this
property for correctness however. For example, creating a StateID with an
invalid value can be done in entirely safe code. This may in turn result in
panics or silent logical errors.
Implementations
impl PatternID
const MAX: PatternID = _;The maximum value.
const LIMIT: usize = SmallIndex::LIMIT;The total number of values that can be represented.
const ZERO: PatternID = _;The zero value.
const SIZE: usize = SmallIndex::SIZE;The number of bytes that a single value uses in memory.
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.
const fn new_unchecked(value: usize) -> PatternIDCreate 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.
const fn from_u32_unchecked(index: u32) -> PatternIDCreate a new value from a
u32without checking whether the given value 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.
fn must(value: usize) -> PatternIDLike
new, but panics if the given value is not valid.const fn as_usize(&self) -> usizeReturn the internal value as a
usize. This is guaranteed to never overflowusize.const fn as_u64(&self) -> u64Return the internal value as a
u64. This is guaranteed to never overflow.const fn as_u32(&self) -> u32Return the internal value as a
u32. This is guaranteed to never overflowu32.const fn as_i32(&self) -> i32Return the internal value as a
i32. This is guaranteed to never overflow ani32.fn one_more(&self) -> usizeReturns one more than this value as a usize.
Since values represented by a "small index" have constraints on their maximum value, adding
1to it will always fit in ausize,u32and ai32.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.
fn from_ne_bytes_unchecked(bytes: [u8; 4]) -> PatternIDDecode this value from the bytes given using the native endian byte order for the current target.
This is analogous to
new_uncheckedin that is does not check whether the decoded integer is representable as a small index.fn to_ne_bytes(&self) -> [u8; 4]Return the underlying integer as raw bytes in native endian format.
Trait Implementations
impl Clone for PatternID
fn clone(&self) -> Self
impl Copy for PatternID
impl Debug for PatternID
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Default for PatternID
fn default() -> Self
impl Eq for PatternID
impl From<u8> for PatternID
fn from(value: u8) -> PatternID
impl Hash for PatternID
fn hash<__H: Hasher>(&self, state: &mut __H)
impl Ord for PatternID
fn cmp(&self, other: &Self) -> Ordering
impl PartialEq for PatternID
fn eq(&self, other: &Self) -> bool
impl PartialOrd for PatternID
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
impl StructuralPartialEq for PatternID
impl TryFrom<u16> for PatternID
type Error = PatternIDError;fn try_from(value: u16) -> Result<PatternID, PatternIDError>
impl TryFrom<u32> for PatternID
type Error = PatternIDError;fn try_from(value: u32) -> Result<PatternID, PatternIDError>
impl TryFrom<u64> for PatternID
type Error = PatternIDError;fn try_from(value: u64) -> Result<PatternID, PatternIDError>
impl TryFrom<usize> for PatternID
type Error = PatternIDError;fn try_from(value: usize) -> Result<PatternID, PatternIDError>
Auto Trait Implementations
impl Freeze for PatternID
impl RefUnwindSafe for PatternID
impl Send for PatternID
impl Sync for PatternID
impl Unpin for PatternID
impl UnsafeUnpin for PatternID
impl UnwindSafe for PatternID
Blanket Implementations
impl<T> Any for PatternID
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for PatternID
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for PatternID
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for PatternID
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for PatternID
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for PatternID
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T, U> Into<U> for PatternID
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 PatternID
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for PatternID
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>