Struct aho_corasick::util::primitives::StateID
source · #[repr(transparent)]pub struct StateID(SmallIndex);
Expand description
The identifier of a finite automaton state.
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 StateID
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.
Tuple Fields§
§0: SmallIndex
Implementations§
source§impl StateID
impl StateID
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<StateID, StateIDError>
pub fn new(value: usize) -> Result<StateID, StateIDError>
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) -> StateID
pub const fn new_unchecked(value: usize) -> StateID
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 from_u32_unchecked(index: u32) -> StateID
pub const fn from_u32_unchecked(index: u32) -> StateID
Create a new value from a u32
without 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.
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<StateID, StateIDError>
pub fn from_ne_bytes(bytes: [u8; 4]) -> Result<StateID, StateIDError>
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]) -> StateID
pub fn from_ne_bytes_unchecked(bytes: [u8; 4]) -> StateID
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.
sourcepub(crate) fn iter(len: usize) -> StateIDIter ⓘ
pub(crate) fn iter(len: usize) -> StateIDIter ⓘ
Returns an iterator over all values from 0 up to and not including the given length.
If the given length exceeds this type’s limit, then this panics.
Trait Implementations§
source§impl From<SmallIndex> for StateID
impl From<SmallIndex> for StateID
source§fn from(index: SmallIndex) -> StateID
fn from(index: SmallIndex) -> StateID
source§impl From<StateID> for SmallIndex
impl From<StateID> for SmallIndex
source§fn from(sid: StateID) -> SmallIndex
fn from(sid: StateID) -> SmallIndex
source§impl Ord for StateID
impl Ord for StateID
source§impl PartialOrd for StateID
impl PartialOrd for StateID
impl Copy for StateID
impl Eq for StateID
impl StructuralPartialEq for StateID
Auto Trait Implementations§
impl Freeze for StateID
impl RefUnwindSafe for StateID
impl Send for StateID
impl Sync for StateID
impl Unpin for StateID
impl UnwindSafe for StateID
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)