pub trait StateID:
Sealed
+ Clone
+ Copy
+ Debug
+ Eq
+ Hash
+ PartialEq
+ PartialOrd
+ Ord {
// Required methods
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§
Sourcefn from_usize(n: usize) -> Self
fn from_usize(n: usize) -> Self
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.
Sourcefn to_usize(self) -> usize
fn to_usize(self) -> usize
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
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.