krossbar-state-machine

Crates.iokrossbar-state-machine
lib.rskrossbar-state-machine
version0.5.4
sourcesrc
created_at2024-06-10 14:44:37.18589
updated_at2024-06-12 18:45:21.420313
descriptionKrossbar state machine
homepagehttps://krossbar.rs
repositoryhttps://github.com/krossbar-platform/krossbar-common
max_upload_size
id1267217
size10,062
Alexander Smoktal (alexander-smoktal)

documentation

README

Crates.io MIT licensed Build Status

krossbar-state-machine

Krossbar state machine

Flat state machine used in several Krossbar services.

The library provides a structure, which is able to support internal state inside async functions. This allows using it as a client state machine. As a standalone library is not so useful if you don't need its specific functionality.

Examples

use krossbar_machine::{control::Control, machine::Machine};

async fn up_to_45(value: i32) -> Control<i32, i32> {
    if value < 45 {
        Control::Loop(value + 1)
    } else {
        Control::Return(value)
    }
}

fn hello(value: i32) -> String {
    format!("Hello {value}!")
}

async fn example() {
    let mach = Machine::init(42).then(up_to_45).ret(hello);

    assert_eq!("Hello 45!", mach.await);
}
Commit count: 99

cargo fmt