sml/lib.rs
1//! # sml.rs
2//!
3//! A `no_std` state-machine library whose primary [`sml!`] procedural macro
4//! mirrors the `sml.cpp` transition-table DSL.
5#![doc = include_str!("../docs/dsl.md")]
6#![no_std]
7
8extern crate self as sml;
9
10pub use sml_macros::sml;
11
12pub mod utility;
13
14/// Common synchronous interface implemented by generated state machines that
15/// do not require a temporary context.
16pub trait Machine<E> {
17 /// Generated state enum.
18 type State;
19
20 /// Processes one event to run-to-completion and reports whether it was
21 /// accepted.
22 fn process_event(&mut self, event: E) -> bool;
23
24 /// Processes one event to run-to-completion and returns its acceptance as a
25 /// future. The default inline path does not allocate.
26 #[inline]
27 fn process_event_async(&mut self, event: E) -> impl core::future::Future<Output = bool> {
28 core::future::ready(self.process_event(event))
29 }
30}
31
32/// Reports whether a state machine has reached its terminal state.
33pub trait Terminated {
34 /// Returns true after entering the generated `X` state.
35 fn is_terminated(&self) -> bool;
36}