#state-machine #fsm #state #machine

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

#2626 in Algorithms

Download history 20/week @ 2024-09-22 1/week @ 2024-09-29 79/week @ 2024-10-27

79 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.6–1.1MB
~22K SLoC