Crates.io | lin-state |
lib.rs | lin-state |
version | 0.0.1 |
source | src |
created_at | 2023-06-30 16:40:31.648466 |
updated_at | 2023-06-30 16:40:31.648466 |
description | Writing state machine in a linear way. This library is part of a larger project, available at the homepage of the library. |
homepage | |
repository | https://github.com/viddrobnic/lin-state |
max_upload_size | |
id | 904761 |
size | 14,078 |
This project explores writing programs which are inherently state machines in a more linear way and making them type safe. It achieves this by heavily using Rust type system, ownership and async implementation.
Specifically, it focuses on easing the writing of programs for embedded devices and robotics,
where a program is often a state machine that works with resources (i.e. sensors, outputs, motors, ...).
Idea comes from the Rust's async implementation, where a future is a state machine and async/await
syntax
is a syntactic sugar for working with futures. A great explanation of this can be found in
tokio's tutorial. This project aims to do a similar
simplification for programs that are inherently state machines.
It does this in three parts:
async/await
syntax.lin-state
library that implements guards, which are used to ensure the
state of the resources is valid during longer action.
Example of such use is again a program that controls a motor which can only move if the doors
of the machine are closed. We can use a door guard to ensure that the doors are closed while moving
the motor. If at any point the doors are opened, the motor will stop moving. In fact, the whole
block of code inside the guard will stop executing.The first two parts are just guidelines on how to write the code. The third part is the library contained in this repository.
This project is not yet complete. The following is a list of things that still need to be done: