Director is a simple, versatile, ergonomic state machine in Rust-lang.

Related tags

Utilities director
Overview

Director

Director is a simple, versatile, ergonomic state machine in Rust-lang. (no-std)

CI Crates.io Licensed Twitter

| Examples | Docs | Latest Note |

director = "0.5.0"

Why?

Because writing state-machine is kind of tedious. Not for human way. It is difficult to achieve flexibility, readability and more analyzability to the architecture. This crate gives all of them. And well optimized[ex:) RAII]. So you don't need to worry way bad performance for your implementation.

How to use,

use crate::Engine; // Any common state

#[director::state {
    super = StateBaz,
    sub = [StateBar, StateBar2]
}]
pub struct StateFoo {
    count: u32,
}

impl director::State<Engine> for StateFoo {
    /// This determines whether or not to run this local state machine.
    fn toggle(engine: &mut Engine, inner: Option<&Self>) -> bool {
        director::on!(inner, None) || director::off!(state: StateBaz, Some(state) if state.count > 1000)
    }
    /// This creates and imports new initial state on this local state machine when the toggle's on.
    fn load(engine: &mut Engine) -> Self {
        Self { count: Self::lock_super__state_baz().get().count }
    }
    /// This executes custom logics and manipulates this local state machine's states.
    fn run(&mut self, engine: &mut Engine) {
        self.count += 1;
        println!("{}", self.count);
    }
    /// When the toggle's off
    fn drop(&self, engine: &mut Engine) {
        // ...
        // After then, the sub states[i.e) StateBar and StateBar2] will be droped automatically.
    }
}
pub struct Engine; // i.e) dummy engine

#[director::main(std::sync)] // It can be any kind of Mutex
fn main() {
    let mut engine = Engine;
    for _ in 0..10000 {
        StateBaz::run(&mut engine);
    }
}
You might also like...
Simple ray tracer written in Rust
Simple ray tracer written in Rust

Simple ray tracer written in Rust from scratch I've just finished my first semester at the Faculty of Applied Mathematics and Computer Science at the

Simple RSA VDF in Rust

Simple RSA VDF in Rust

Simple Spreadsheet editor written in Rust

Rexcel Simple Spreadsheet editor written in Rust Keyboard Shortcuts: CTRL + S = Save CTRL + Q = Quit CTRL + W + Save And Quit CTRL + ALT + S = Sav

A simple omegle API written in Rust

omegalul-rs omegalul-rs is a work-in-progress opensource library for building Omegle clients. Features Current Features Fetching random server from om

Simple interoperability between C++ coroutines and asynchronous Rust

cxx-async Overview cxx-async is a Rust crate that extends the cxx library to provide seamless interoperability between asynchronous Rust code using as

A simple code boilerplate generator written in Rust.

💻 Cgen What is Cgen? A modern, cross-platform, multi-language boilerplate generator aimed to make your code generation less hectic! If you wish to su

A simple string interner / symbol table for Rust projects.

Symbol Interner A small Rust crate that provides a naïve string interner. Consult the documentation to learn about the types that are exposed. Install

Simple and efficient time representation in Rust.

timens-rs Simple and efficient timestamp representation. The main objective being interoperability with OCaml Core_kernel.Time_ns. A significant part

A Rust crate that provides a simple interface for LZMA compression and decompression.

rust-lzma Documentation This crate provides a simple interface to liblzma. LZMA is more commonly known as XZ or 7zip, (as in, files with the .xz or .7

Comments
  • Currently using `static Mutex<Option<State>>` has a huge overhead.

    Currently using `static Mutex>` has a huge overhead.

    I made a simple state machine as a counter for this one specific benchmark and the result showed -2500% efficiency. I wanted the state machines have capability with multi-threading programming but before considering that i think we need to think about how to solve this simple efficiency problem. Well, there is one solution to solve this problem, It is whether to use Mutex or make a synchronous state machine, leaving optionally the user's choice.

    enhancement 
    opened by just-do-halee 0
Releases(v0.5.0)
Owner
Doha Lee
I will change the world.
Doha Lee
Component-based state machine plugin for Bevy

seldom_state is a component-based state machine plugin for Bevy. It's useful for AI, player state, and other entities that occupy various states. It allows for greater reusability of state logic between entities, compared to managing mutually-exclusive components directly in your systems.

Seldom 43 Jan 2, 2023
A simple script (in Rust lang) to create HTML from SVD

A simple script to create HTML from an SVD file This is a simple script written in Rust language to create a single HTML file from an SVD file. It's r

Björn Quentin 14 Aug 22, 2022
A fork of 'discord-token-botter' for rust lang.

Shahzain Botter V3(Rust) - If you were sold this tool, you have been scammed, this tool is free & open source Please DO NOT pay money for this tool A

Shahzain 5 Nov 7, 2022
High-performance, Reliable ChatGLM SDK natural language processing in Rust-Lang

RustGLM for ChatGLM Rust SDK - 中文文档 High-performance, high-quality Experience and Reliable ChatGLM SDK natural language processing in Rust-Language 1.

Blueokanna 3 Feb 29, 2024
A simple interpreter for the mathematical random-access machine

Random-access machine runner A simple Rust RAM program runner. Lexer/Parser Program executor Code formatter Web Compiled to WASM to run in the browser

Marcin Wojnarowski 5 Jan 14, 2023
Rust experiments involving Haskell-esque do notation, state, failure and Nom parsers!

Introduction As a long time Haskell developer recently delving into Rust, something I've really missed is monads and do notation. One thing monadic do

Kerfuffle 23 Feb 28, 2022
💫 Small microservice to handle state changes of Kubernetes pods and post them to Instatus or Statuspages

?? Kanata Small microservice to handle state changes of Kubernetes pods and post to Instatus ?? Why? I don't really want to implement and repeat code

Noel ʕ •ᴥ•ʔ 4 Mar 4, 2022
A lightning fast state management module for Yew.

yewv A lightning fast state management module for Yew built with performance and simplicity as a first priority. Who is this for? If you wish to use a

null 7 Dec 8, 2022
Detect if code is running inside a virtual machine (x86 and x86-64 only).

inside-vm Detect if code is running inside a virtual machine. Only works on x86 and x86-64. How does it work Measure average cpu cycles when calling c

null 34 Oct 3, 2022
Code for connecting an RP2040 to a Bosch BNO055 IMU and having the realtime orientation data be sent to the host machine via serial USB

Code for connecting an RP2040 (via Raspberry Pi Pico) to a Bosch BNO055 IMU (via an Adafruit breakout board) and having the realtime orientation data be sent to the host machine via serial USB.

Gerald Nash 3 Nov 4, 2022