silk.machine.definition.

The whole chart as data: a Definition can be written to JSON and read back, so external tools can show a machine, and a build step can generate Silk source from one.

Details#

A definition is text all the way down. The effects a row leaves, and the value a transition enters, are written as a program writes them, such as Exits { status: 4 }. A guard is its name, when it has one.

Gotchas#

A value is written from its unions, enums, structs, numbers, booleans and text. A field of another type, such as a list, is written as ...

Import as Definition with import silk.machine.definition { Definition }.

Public declarations: 12.

TransitionDefinition#

silk
pub struct TransitionDefinition

A transition taken on an event.

Field event#

silk
pub event: String

The event's name, or * for a transition that any event takes.

Field target#

silk
pub target: String

The target state, or an empty string for a transition that takes the event and stays.

Field enters#

silk
pub enters: String

The value of the target state as a program writes it, such as Open { floor: 2 }, or an empty string for a transition that stays.

Field guarded#

silk
pub guarded: bool

Whether a guard function decides if the transition is taken.

Field guard#

silk
pub guard: String

The name of the guard, from Guards.named, or an empty string when it has none.

Field refused#

silk
pub refused: String

The reason the state refuses the event, from Chart.refuse, or an empty string for a transition that is not a refusal.

Field history#

silk
pub history: bool

Whether the target is entered from its history, as it was when its chart last left it.

Field leaves#

silk
pub leaves: List<String>

The effects the transition leaves, from Chart.leaves, each as a program writes it. An effect of Chart.leavesWhen ends in when and the name of its guard, or guarded.

Field meta#

silk
pub meta: List<MetaDefinition>

The meta data of the transition.

AlwaysDefinition#

silk
pub struct AlwaysDefinition

A transition taken without an event, as soon as its state is active.

Field target#

silk
pub target: String

Field guarded#

silk
pub guarded: bool

Field guard#

silk
pub guard: String

The name of the condition, from Guards.named, or an empty string when it has none.

Field leaves#

silk
pub leaves: List<String>

The effects the transition leaves, from Chart.leaves, each as a program writes it. An effect of Chart.leavesWhen ends in when and the name of its guard, or guarded.

DelayDefinition#

silk
pub struct DelayDefinition

A transition taken after its state stayed active for duration, in nanoseconds.

Field duration#

silk
pub duration: u64

Field target#

silk
pub target: String

Field leaves#

silk
pub leaves: List<String>

The effects the transition leaves, from Chart.leaves, each as a program writes it. An effect of Chart.leavesWhen ends in when and the name of its guard, or guarded.

RegionDefinition#

silk
pub struct RegionDefinition

A region of a state: a chart of its own that is active while the state is.

Field field#

silk
pub field: String

The name of the field of the state that holds the region.

Field chart#

silk
pub chart: String

The name of the region's chart, one of the charts of the definition.

RememberDefinition#

silk
pub struct RememberDefinition

The history of a state: its value is kept when its chart leaves it.

Field field#

silk
pub field: String

The name of the field of the context that keeps the value.

Field deep#

silk
pub deep: bool

Whether the regions come back whole (deep history) or only their own states (shallow).

MetaDefinition#

silk
pub struct MetaDefinition

One entry of the meta data of a state or of a transition.

Field key#

silk
pub key: String

Field value#

silk
pub value: String

StateDefinition#

silk
pub struct StateDefinition

One state of a chart with the transitions that leave it.

Field name#

silk
pub name: String

Field final#

silk
pub final: bool

Field tags#

silk
pub tags: List<String>

Field meta#

silk
pub meta: List<MetaDefinition>

Field on#

silk
pub on: List<TransitionDefinition>

Field always#

silk
pub always: List<AlwaysDefinition>

Field after#

silk
pub after: List<DelayDefinition>

Field done#

silk
pub done: String

The state taken when every region of this one is in a final state, see Chart.onDone, or an empty string when there is none.

Field awaits#

silk
pub awaits: List<String>

The names of the events the state waits for the world to answer with, from Chart.awaits.

Field regions#

silk
pub regions: List<RegionDefinition>

The regions of the state: none for an atomic state, one for a compound state, several for a parallel state.

Field remember#

silk
pub remember: Option<RememberDefinition>

The history of the state, when it has one.

ChartDefinition#

silk
pub struct ChartDefinition

A chart: its states and which one is entered first.

Field name#

silk
pub name: String

Field initial#

silk
pub initial: String

Field states#

silk
pub states: List<StateDefinition>

Definition#

silk
pub struct Definition

A machine: its chart and the charts of every region below it, each one time.

The charts are a flat list and a region names its chart, so a chart that several states hold as a region is written one time. The first chart is the machine's own.

Field name#

silk
pub name: String

Field charts#

silk
pub charts: List<ChartDefinition>

Implementation Schema for MetaDefinition#

silk
impl Schema for MetaDefinition

Implementation Schema for TransitionDefinition#

silk
impl Schema for TransitionDefinition

Implementation Schema for AlwaysDefinition#

silk
impl Schema for AlwaysDefinition

Implementation Schema for DelayDefinition#

silk
impl Schema for DelayDefinition

Implementation Schema for RegionDefinition#

silk
impl Schema for RegionDefinition

Implementation Schema for RememberDefinition#

silk
impl Schema for RememberDefinition

Implementation Schema for StateDefinition#

silk
impl Schema for StateDefinition

Implementation Schema for ChartDefinition#

silk
impl Schema for ChartDefinition

Implementation Schema for Definition#

silk
impl Schema for Definition

Durations#

silk
pub struct Durations

Implementation Durations#

silk
impl Durations

Associated function literal#

silk
pub fn literal(duration: u64, buffer: &mut [u8; 48]) -> usize

Writes duration, in nanoseconds, as a duration literal such as 1m30s at the start of buffer, and returns the length of the text. Zero is 0ns.

Definitions#

silk
pub struct Definitions

Implementation Definitions#

silk
impl Definitions

Associated function of#

silk
pub effect fn of<S: Machine<E, C, X>, E, C, X>() -> Definition
    ! OutOfMemoryError
    ? &mut Allocator

Returns the definition of the machine S: its chart first, then the chart of each region.

Associated function find#

silk
pub fn find(definition: &Definition, name: string) -> usize

Returns the position in definition.charts of the chart called name, or the number of charts when there is none.

Values#

silk
pub struct Values

Writes values as text for a Definition.

Implementation Values#

silk
impl Values

Associated function write#

silk
pub effect fn write<T>(value: &T, text: &mut String) -> ()
    ! OutOfMemoryError
    ? &mut Allocator

Appends value to text as a program writes it: Exits { status: 4 } for a variant of a union, Archive for a member of an enum, Point { x: 1, y: 2 } for a struct, and the digits or the word for a number or a boolean. Text is written in double quotes without escapes. A field of any other type, such as a list, is written as ...

Category: State machines.

Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2, x86_64-pc-windows-msvc, wasm64-unknown-unknown.

View the source of this page