pub struct Machine { /* private fields */ }Expand description
A compiled chart: an immutable value, cheap to clone, that any number of threads may share.
compile answers one. Cloning a machine shares it
rather than copying it.
let machine = statifier::compile(
r#"<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0"><state id="a"/></scxml>"#,
)?;
let shared = machine.clone();
std::thread::spawn(move || assert!(shared.warnings().is_empty())).join().unwrap();Implementations§
Source§impl Machine
impl Machine
Sourcepub fn check_accepts(&self, declared: Option<&[&str]>) -> AcceptsCheck
pub fn check_accepts(&self, declared: Option<&[&str]>) -> AcceptsCheck
Compares declared, the event names the chart is declared to
accept, with the chart’s event vocabulary: every event descriptor on
a transition whose source state some path enters, as the document
writes it, each once, states in document order and a state’s own
transitions before its children’s. A pattern is a descriptor as
written (*, e.*, e.), never expanded, and a descriptor on a
state no path enters is not in the vocabulary.
A descriptor matches a declared name as transition selection matches
an event, on token boundaries: a declared e.go is matched by e.go,
e.*, e., e and *, and not by e.gone or e.go.now. A
declared name is a name, never a pattern: a * in it is an ordinary
token, so a declared e.* is matched by e but not by e.go.
None is no declaration: the computed vocabulary is the contract,
which cannot disagree with itself, so both lists are empty. An empty
declaration declares that the chart accepts nothing: no name is
unreachable and every descriptor is undeclared. Asked with one name,
unreachable is the membership answer: empty when some descriptor in
the vocabulary matches it.
It reads the compiled chart alone, runs nothing and refuses nothing; which list a host refuses a deployment on, if either, is the host’s decision.
let machine = statifier::compile(
r#"<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0">
<state id="a">
<transition event="e.go" target="b"/>
<transition event="e.*"/>
</state>
<state id="b"><transition event="x"/></state>
<state id="c"><transition event="y"/></state>
</scxml>"#,
)?;
// No declaration: nothing to disagree with.
let none = machine.check_accepts(None);
assert!(none.unreachable.is_empty() && none.undeclared.is_empty());
// An empty declaration: every descriptor some path reaches is
// undeclared, and `y`, on a state no path enters, is not one.
let empty = machine.check_accepts(Some(&[]));
assert_eq!(empty.undeclared, ["e.go", "e.*", "x"]);
let check = machine.check_accepts(Some(&["e.go", "y"]));
assert_eq!(check.unreachable, ["y"]);
assert_eq!(check.undeclared, ["x"]);Source§impl Machine
impl Machine
Sourcepub fn import_position(&self, position: &Position) -> Result<State, ImportError>
pub fn import_position(&self, position: &Position) -> Result<State, ImportError>
A chart in execution over this machine, at position: the reverse
of State::export_position. The position’s identity is not read,
so a position may be imported into any chart that holds every state
it names.
The root is re-added to the configuration and to the entered states,
and the internal queue starts empty. The driver’s own fields start
as a fresh session’s do: the virtual clock at 0, no pending timer,
no queued external event, not halted. The session id is the
datamodel’s _sessionid, and the registered send types are the
entries of _ioprocessors other than the SCXML Event I/O
Processor’s, as Machine::start writes them. A position carries
no child session, so a live invocation it names has none: it is
sent nothing, forwarded nothing and returns nothing, and its state’s
exit cancels it.
A stopped position imports stopped: State::done answers, and
State::step refuses. A position carries no donedata and a stopped
chart’s configuration is empty, so Done::donedata is
Value::Undefined and Done::configuration the position’s own.
Refused, in this order, with ImportError::NoSessionId when
_sessionid is not a string; with ImportError::UnknownStateIds,
naming every one, when the position names a state the chart does not
hold; with ImportError::InvalidHistoryValue when a recorded
history value is not one the chart can restore; and, live invocation
by live invocation, with ImportError::UnknownInvoke when one names
an <invoke> its state does not hold and with
ImportError::DuplicateInvocation when two name one <invoke>. Every state the position names is checked against
the chart before any of it is read.
Source§impl Machine
impl Machine
Sourcepub fn start(&self, options: Options) -> Result<Moved, Error>
pub fn start(&self, options: Options) -> Result<Moved, Error>
Starts the chart: its datamodel bound, its <scxml> scripts run, its
initial states entered, and the whole run to a stable configuration,
with every event it sent itself taken.
Refused with Error::BuiltInSendTypes when options registers a
built-in send type, then with Error::UnregisteredEntries when it
gives an _ioprocessors entry for a type it does not register.