sairun

Crates.iosairun
lib.rssairun
version0.1.0
created_at2025-03-22 09:30:43.109749+00
updated_at2025-03-22 09:30:43.109749+00
descriptionAn async runtime for sans-IO code
homepage
repository
max_upload_size
id1601684
size11,792
Thomas Eizinger (thomaseizinger)

documentation

README

sairun - sans-IO async runtime

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!

Essentially, sairun is just a sans-IO component itself that acts as a bridge between its Futures and your actual IO code.

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());
    }
}
Commit count: 0

cargo fmt