asansio
Async/await state machine for the Sans I/O design pattern.
The Idea
This crate is a experiment for Sans I/O in Rust (see sans I/O for network protocols documentation to familiar with the concept). Writing network protocol without performing I/O operations means creating a state machine. Manually creating a state machine could be a tedious process. As Rust async/await concept is an actual state machine with implicit states created during compilation, this library is an experiment with using async/await to provide such state machine automatically. Let's check if this is good solution to the problem.
Dependency
It is no_std crate without allocations on the heap. It depends only on the
core, no other crates. Only examples uses std, clap and tokio as
dev-dependencies.
Usage
You can provide async iface trait that can handle all SansIo handling. This way you can use single protocol defined in async way with std or async runtime.
This is the example of std interface and client:
use Io;
use IoHandle;
use Sans;
use Pin;
async
type Request = ;
type Response = ;
let mut client = new.unwrap;
assert_eq!;
assert_eq!;
assert_eq!;
The crate divides a problem into two parts. The first Sans takes care of the
state machine independent of the I/O and the second Io is responsible with
I/O communication. These two parts communicate using Request and Respond
types, which are defined by the user (for real scenarios they could be
enums).
See also more examples.
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.