https://github.com/thomaseizinger/sairun
An async runtime for sans-IO code.
https://github.com/thomaseizinger/sairun
Last synced: about 1 year ago
JSON representation
An async runtime for sans-IO code.
- Host: GitHub
- URL: https://github.com/thomaseizinger/sairun
- Owner: thomaseizinger
- Created: 2025-03-22T02:26:07.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-22T09:31:56.000Z (about 1 year ago)
- Last Synced: 2025-03-22T10:19:15.519Z (about 1 year ago)
- Language: Rust
- Homepage:
- Size: 9.77 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# sairun - **sa**ns-**I**O async **run**time
sairun is an experimental async runtime for sans-IO implementations.
sans-IO is cool but it is annoying that we have to write our own state machines for handling what are essentially async operations.
It would be much better if we could just use async/await and let the compiler handle composing for us.
With sairun, you can now do this! (on nightly)
Essentially, `sairun` is just a sans-IO component itself that acts as a bridge between its `Future`s and your actual IO code.
```rust
async fn greet() {
let src = "127.0.0.1:1234".parse().unwrap();
let dst = "192.168.0.1:5678".parse().unwrap();
sairun::udp::send_to(src, dst, "Hello".as_bytes().to_vec()).await;
let msg = sairun::udp::recv_from(src, dst).await;
let msg = String::from_utf8(msg).unwrap();
println!("Received '{msg}' from {dst}");
}
#[test]
fn send_receive() {
let mut runtime = sairun::Runtime::default();
runtime.spawn(greet(), Instant::now());
loop {
if let Some(msg) = runtime.poll_datagram() {
// Use an actual socket to send the UDP datagram
}
let (local, remote, msg) = todo!("receive datagram from a socket");
runtime.handle_input(local, remote, msg, Instant::now());
}
}
```