All Projects → hashmismatch → finny.rs

hashmismatch / finny.rs

Licence: other
Finite State Machines for Rust

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to finny.rs

Nebuchadnezzar
High Performance Key-Value Store
Stars: ✭ 49 (+2.08%)
Mutual labels:  rust-library
ghakuf
A Rust library for parsing/building SMF (Standard MIDI File).
Stars: ✭ 30 (-37.5%)
Mutual labels:  rust-library
akka-cqrs-activator
Issue tracker PoC application written in Scala (Akka) and JavaScript (React) that demonstrates event sourcing and CQRS
Stars: ✭ 33 (-31.25%)
Mutual labels:  fsm
vfin
🦈 GUI framework agnostic virtual DOM library
Stars: ✭ 17 (-64.58%)
Mutual labels:  rust-library
rust-phonenumber
Library for parsing, formatting and validating international phone numbers.
Stars: ✭ 99 (+106.25%)
Mutual labels:  rust-library
shell2batch
Coverts simple basic shell scripts to windows batch scripts.
Stars: ✭ 42 (-12.5%)
Mutual labels:  rust-library
arangors
Easy to use rust driver for arangoDB
Stars: ✭ 120 (+150%)
Mutual labels:  rust-library
imgref
A trivial Rust struct for interchange of pixel buffers with width, height & stride
Stars: ✭ 45 (-6.25%)
Mutual labels:  rust-library
colorful
Make your terminal output colorful.
Stars: ✭ 43 (-10.42%)
Mutual labels:  rust-library
rsmorphy
Morphological analyzer / inflection engine for Russian and Ukrainian languages rewritten in Rust
Stars: ✭ 27 (-43.75%)
Mutual labels:  rust-library
contour-rs
Contour polygon creation in Rust (using marching squares algorithm)
Stars: ✭ 33 (-31.25%)
Mutual labels:  rust-library
tentacle
A multiplexed p2p network framework that supports custom protocols
Stars: ✭ 41 (-14.58%)
Mutual labels:  rust-library
rustgraphblas
rust-library to wrap GraphBLAS.h
Stars: ✭ 23 (-52.08%)
Mutual labels:  rust-library
LuaCSP
Communicating Sequential Processes in Lua
Stars: ✭ 40 (-16.67%)
Mutual labels:  fsm
type-metadata
Rust type metadata reflection library
Stars: ✭ 27 (-43.75%)
Mutual labels:  rust-library
crc32c
Fast CRC-32-Castagnoli implementation in Rust
Stars: ✭ 26 (-45.83%)
Mutual labels:  rust-library
codebreaker-rs
A Rust library to decrypt & encrypt any cheat code for CodeBreaker PS2
Stars: ✭ 18 (-62.5%)
Mutual labels:  rust-library
httper
An asynchronous HTTP(S) client built on top of hyper.
Stars: ✭ 16 (-66.67%)
Mutual labels:  rust-library
rust-lcms2
ICC color profiles in Rust
Stars: ✭ 25 (-47.92%)
Mutual labels:  rust-library
har-rs
A HTTP Archive format (HAR) serialization & deserialization library, written in Rust.
Stars: ✭ 25 (-47.92%)
Mutual labels:  rust-library

Finny - Hierarchical Finite State Machines for Rust

Crates.io Documentation Build

Features

  • Declarative, builder API with a procedural function macro that generate the dispatcher
  • Compile-time transition graph validation
  • No run-time allocations required, no_std support
  • Support for generics within the shared context
  • Transition guards and actions
  • State regions, also known as orthogonal states
  • Event queueing and run-to-completition execution
  • Submachines, also known as Hierarchical State Machines
  • Timers on states

Example

Cargo.toml

[dependencies]
finny = "0.2"

Code

use finny::{finny_fsm, FsmFactory, FsmResult, decl::{BuiltFsm, FsmBuilder}};

// The context is shared between all guards, actions and transitions. Generics are supported here!
#[derive(Default)]
pub struct MyContext { val: u32 }
// The states are plain structs.
#[derive(Default)]
pub struct MyStateA { n: usize }
#[derive(Default)]
pub struct MyStateB;
// The events are also plain structs. They can have fields.
#[derive(Clone)]
pub struct MyEvent;

// The FSM is generated by a procedural macro
#[finny_fsm]
fn my_fsm(mut fsm: FsmBuilder<MyFsm, MyContext>) -> BuiltFsm {
    // The FSM is described using a builder-style API
    fsm.state::<MyStateA>()
       .on_entry(|state, ctx| {
           state.n += 1;
           ctx.context.val += 1;
        })
       .on_event::<MyEvent>()
       .transition_to::<MyStateB>()
       .guard(|_ev, ctx, _states| { ctx.context.val > 0 })
       .action(|_ev, ctx, state_a, state_b| { ctx.context.val += 1; });
    fsm.state::<MyStateB>();
    fsm.initial_state::<MyStateA>();
    fsm.build()
}

// The FSM is built and tested.
fn main() -> FsmResult<()> {
    let mut fsm = MyFsm::new(MyContext::default())?;
    assert_eq!(0, fsm.val);
    fsm.start()?;
    let state_a: &MyStateA = fsm.get_state();
    assert_eq!(1, state_a.n);
    assert_eq!(1, fsm.val);
    fsm.dispatch(MyEvent)?;
    assert_eq!(2, fsm.val);
    Ok(())
}

License: MIT OR Apache-2.0

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].