feat(core): Add associated 'Error' type to FSM trait
Adds an associated 'Error' type that can be returned by actions when an interpretation fails.
This commit is contained in:
parent
406a90e8d6
commit
37590ae0f6
1 changed files with 6 additions and 1 deletions
|
@ -108,6 +108,7 @@
|
||||||
//!
|
//!
|
||||||
//! Please reach out! I want to know why!
|
//! Please reach out! I want to know why!
|
||||||
|
|
||||||
|
use std::fmt::Debug;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
/// Primary trait that needs to be implemented for every state type
|
/// Primary trait that needs to be implemented for every state type
|
||||||
|
@ -129,6 +130,10 @@ pub trait FSM where Self: Sized {
|
||||||
/// actions that can occur in the state-machine.
|
/// actions that can occur in the state-machine.
|
||||||
type Action;
|
type Action;
|
||||||
|
|
||||||
|
/// The associated error type of an FSM represents failures that
|
||||||
|
/// can occur during action processing.
|
||||||
|
type Error: Debug;
|
||||||
|
|
||||||
/// `handle` deals with any incoming events to cause state
|
/// `handle` deals with any incoming events to cause state
|
||||||
/// transitions and emit actions. This function is the core logic
|
/// transitions and emit actions. This function is the core logic
|
||||||
/// of any state machine.
|
/// of any state machine.
|
||||||
|
@ -152,7 +157,7 @@ pub trait FSM where Self: Sized {
|
||||||
|
|
||||||
/// `act` interprets and executes FSM actions. This is the only
|
/// `act` interprets and executes FSM actions. This is the only
|
||||||
/// part of an FSM in which side-effects are allowed.
|
/// part of an FSM in which side-effects are allowed.
|
||||||
fn act(Self::Action) -> Vec<Self::Event>;
|
fn act(Self::Action) -> Result<Vec<Self::Event>, Self::Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This function is the primary function used to advance a state
|
/// This function is the primary function used to advance a state
|
||||||
|
|
Loading…
Reference in a new issue