pub trait Events: Copy {
// Required methods
fn index(&self) -> usize;
fn from_index(index: usize) -> Self;
}Expand description
Trait for event types that trigger state transitions.
Implement this trait to define the events that can cause state transitions in your DFA. Each event must be convertible to and from a unique index.
§Example
use tinystate::Events;
#[derive(Debug, Clone, Copy)]
enum DoorEvent {
Push,
Pull,
Lock,
}
impl Events for DoorEvent {
fn index(&self) -> usize {
*self as usize
}
fn from_index(i: usize) -> Self {
match i {
0 => Self::Push,
1 => Self::Pull,
2 => Self::Lock,
_ => unreachable!(),
}
}
}Or you can use the #[derive(Events)] macro to automatically do this. (Works only on unfielded enums)
Required Methods§
Sourcefn from_index(index: usize) -> Self
fn from_index(index: usize) -> Self
Constructs an event from its index.
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.