Expand description

Implementation of a generic finite state machine with extended state. Features worth mentioning:

  • optional exit/enter transitions on states
  • each event instance can provide boxed arguments to transiton closure
  • each transition closure can return with vector of arguments that are queued at the end of outstanding events queue
  • can generate dot representation of itself, edges are grouped on color and annotated with events and optional names to provide readable, dense representation for dense graphs

Author

Tony Przygienda, 2016

Examples

Check out the tests in the implementation for a good example of use

Panics

Never

Errors

refer to Errors

Copyrights

Copyright (c) 2017, Juniper Networks, Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. This code is not an official Juniper product. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Structs

stores the transition

Finite state machine type

describes a transition origination point

implements the target of a transition upon an event

Enums

available dot colors for the transition destinations

types of transitions on states

Errors that can occur when running FSMs

Traits

trait that can process events from a queue using a transition table

Type Definitions

transition function to either enter or exit a specific state, return same as FSMTransitionFn. StateType passed in is previous state before currently entered or exited state. EventType is indicating which event causes the enter or exit. This allows to track where an FSM entered or exited a state from which can be of high interest in “stable” states of the FSM. In case of Entry on the first state it may be all None.

set of events to execute with according optional argument on call of transition function

type representing an optional argument to a transition function call

transition function used, takes optional argument and returns either with error or an optional set of events to be added to processing (at the end of event queue)

type to be returned by all transitions an optional vector of events to be added to the FSM event queue or an error is returned