#state-machine #state #machine #fsm #rust

nefsm

A simple state machine library for Rust

3 releases

0.1.3 Apr 4, 2023
0.1.2 Apr 3, 2023
0.1.0 Feb 24, 2023

#2217 in Algorithms

Download history 10/week @ 2024-02-11 7/week @ 2024-02-18 24/week @ 2024-02-25 1/week @ 2024-03-03 8/week @ 2024-03-10 1/week @ 2024-03-17 49/week @ 2024-03-31

58 downloads per month

MIT license

17KB
265 lines

nefsm

nefsm is a Rust library for implementing finite state machines. It provides a flexible and reusable way to create state machines, allowing developers to more easily reason about complex systems and design more robust and reliable software.

Installation

To use nefsm in your Rust project, simply add it to your Cargo.toml file:

[dependencies]
nefsm = "0.1.0"

lib.rs:

A simple state machine library for Rust, using enums for states and events.

This library provides a simple, flexible way to define state machines in Rust. The states and events are defined using Rust enums, and the state machine itself is a generic struct that can be instantiated with any specific set of enums.

The core traits used in this library are FsmEnum, and Stateful.

  • FsmEnum is a trait that defines how to create a new state machine state based on a given enum value. This is used to instantiate new state machine states when a state transition occurs.

  • Stateful is a trait that defines how a state should handle state transition events.

  • StateMachine is the main struct that represents a state machine instance. It tracks the current state, and provides methods to initialize the state machine, process events, and get the current state.

This library is designed to be easy to use and flexible enough to handle a wide variety of state machine designs.

Dependencies

~0.7–1.2MB
~25K SLoC