pub struct State {
pub action: Option<Action>,
pub counter: (Option<Counter>, Option<Counter>),
/* private fields */
}
Expand description
A state as part of a Machine
.
Fields§
§action: Option<Action>
Take an action upon transitioning to this state.
counter: (Option<Counter>, Option<Counter>)
On transition to this state, update the machine’s two counters (A,B).
Implementations§
Source§impl State
impl State
Sourcepub fn new(t: EnumMap<Event, Vec<Trans>>) -> Self
pub fn new(t: EnumMap<Event, Vec<Trans>>) -> Self
Create a new State
that transitions on the given Event
s.
Example:
use maybenot::state::*;
use maybenot::event::*;
use enum_map::enum_map;
let state = State::new(enum_map! {
Event::PaddingSent => vec![Trans(1, 1.0)],
Event::CounterZero => vec![Trans(2, 1.0)],
_ => vec![],
});
This creates a state that transitions to state 1 on
Event::PaddingSent
and to state 2 on Event::CounterZero
, both
with 100% probability. All other events will not cause a transition.
Note that state indexes are 0-based and determined by the order in which
states are added to the Machine
.
Sourcepub fn validate(&self, num_states: usize) -> Result<(), Error>
pub fn validate(&self, num_states: usize) -> Result<(), Error>
Validate that this state has acceptable transitions and that the
distributions, if set, are valid. Note that num_states is the number of
states in the machine, not the number of states in this state’s
transitions. Called by Machine::new
.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for State
impl<'de> Deserialize<'de> for State
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for State
impl RefUnwindSafe for State
impl Send for State
impl Sync for State
impl Unpin for State
impl UnwindSafe for State
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
Mutably borrows from an owned value. Read more