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#
pub struct TransitionDefinitionA transition taken on an event.
Field event#
pub event: StringThe event's name, or * for a transition that any event takes.
Field target#
pub target: StringThe target state, or an empty string for a transition that takes the event and stays.
Field enters#
pub enters: StringThe 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#
pub guarded: boolWhether a guard function decides if the transition is taken.
Field guard#
pub guard: StringThe name of the guard, from Guards.named, or an empty string when it has none.
Field refused#
pub refused: StringThe reason the state refuses the event, from Chart.refuse, or an empty string for a
transition that is not a refusal.
Field history#
pub history: boolWhether the target is entered from its history, as it was when its chart last left it.
Field leaves#
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#
pub meta: List<MetaDefinition>The meta data of the transition.
AlwaysDefinition#
pub struct AlwaysDefinitionA transition taken without an event, as soon as its state is active.
Field target#
pub target: StringField guarded#
pub guarded: boolField guard#
pub guard: StringThe name of the condition, from Guards.named, or an empty string when it has none.
Field leaves#
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#
pub struct DelayDefinitionA transition taken after its state stayed active for duration, in nanoseconds.
Field duration#
pub duration: u64Field target#
pub target: StringField leaves#
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#
pub struct RegionDefinitionA region of a state: a chart of its own that is active while the state is.
Field field#
pub field: StringThe name of the field of the state that holds the region.
Field chart#
pub chart: StringThe name of the region's chart, one of the charts of the definition.
RememberDefinition#
pub struct RememberDefinitionThe history of a state: its value is kept when its chart leaves it.
Field field#
pub field: StringThe name of the field of the context that keeps the value.
Field deep#
pub deep: boolWhether the regions come back whole (deep history) or only their own states (shallow).
MetaDefinition#
pub struct MetaDefinitionOne entry of the meta data of a state or of a transition.
Field key#
pub key: StringField value#
pub value: StringStateDefinition#
pub struct StateDefinitionOne state of a chart with the transitions that leave it.
Field name#
pub name: StringField final#
pub final: boolField tags#
pub tags: List<String>Field meta#
pub meta: List<MetaDefinition>Field on#
pub on: List<TransitionDefinition>Field always#
pub always: List<AlwaysDefinition>Field after#
pub after: List<DelayDefinition>Field done#
pub done: StringThe 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#
pub awaits: List<String>The names of the events the state waits for the world to answer with, from Chart.awaits.
Field regions#
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#
pub remember: Option<RememberDefinition>The history of the state, when it has one.
ChartDefinition#
pub struct ChartDefinitionA chart: its states and which one is entered first.
Field name#
pub name: StringField initial#
pub initial: StringField states#
pub states: List<StateDefinition>Definition#
pub struct DefinitionA 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#
pub name: StringField charts#
pub charts: List<ChartDefinition>Implementation Schema for MetaDefinition#
impl Schema for MetaDefinitionImplementation Schema for TransitionDefinition#
impl Schema for TransitionDefinitionImplementation Schema for AlwaysDefinition#
impl Schema for AlwaysDefinitionImplementation Schema for DelayDefinition#
impl Schema for DelayDefinitionImplementation Schema for RegionDefinition#
impl Schema for RegionDefinitionImplementation Schema for RememberDefinition#
impl Schema for RememberDefinitionImplementation Schema for StateDefinition#
impl Schema for StateDefinitionImplementation Schema for ChartDefinition#
impl Schema for ChartDefinitionImplementation Schema for Definition#
impl Schema for DefinitionDurations#
pub struct DurationsImplementation Durations#
impl DurationsAssociated function literal#
pub fn literal(duration: u64, buffer: &mut [u8; 48]) -> usizeWrites 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#
pub struct DefinitionsImplementation Definitions#
impl DefinitionsAssociated function of#
pub effect fn of<S: Machine<E, C, X>, E, C, X>() -> Definition
! OutOfMemoryError
? &mut AllocatorReturns the definition of the machine S: its chart first, then the chart of each region.
Associated function find#
pub fn find(definition: &Definition, name: string) -> usizeReturns the position in definition.charts of the chart called name, or the number of
charts when there is none.
Values#
pub struct ValuesWrites values as text for a Definition.
Implementation Values#
impl ValuesAssociated function write#
pub effect fn write<T>(value: &T, text: &mut String) -> ()
! OutOfMemoryError
? &mut AllocatorAppends 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.