Skip to main content

Machine

Struct Machine 

Source
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

Source

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

Source

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

Source

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.

Source§

impl Machine

Source

pub fn warnings(&self) -> &[Warning]

The warnings the chart drew, in document order.

Trait Implementations§

Source§

impl Clone for Machine

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Machine

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.