Trait aho_corasick::StateID

source ·
pub trait StateID: Sealed + Clone + Copy + Debug + Eq + Hash + PartialEq + PartialOrd + Ord {
    fn from_usize(n: usize) -> Self;
    fn to_usize(self) -> usize;
    fn max_id() -> usize;
}
Expand description

A trait describing the representation of an automaton’s state identifier.

The purpose of this trait is to safely express both the possible state identifier representations that can be used in an automaton and to convert between state identifier representations and types that can be used to efficiently index memory (such as usize).

In general, one should not need to implement this trait explicitly. Indeed, for now, this trait is sealed such that it cannot be implemented by any other type. In particular, this crate provides implementations for u8, u16, u32, u64 and usize. (u32 and u64 are only provided for targets that can represent all corresponding values in a usize.)

Required Methods§

Convert from a usize to this implementation’s representation.

Implementors may assume that n <= Self::max_id. That is, implementors do not need to check whether n can fit inside this implementation’s representation.

Convert this implementation’s representation to a usize.

Implementors must not return a usize value greater than Self::max_id and must not permit overflow when converting between the implementor’s representation and usize. In general, the preferred way for implementors to achieve this is to simply not provide implementations of StateID that cannot fit into the target platform’s usize.

Return the maximum state identifier supported by this representation.

Implementors must return a correct bound. Doing otherwise may result in unspecified behavior (but will not violate memory safety).

Implementations on Foreign Types§

Implementors§