2 releases

0.0.1 Nov 24, 2024
0.0.0 Oct 24, 2024

#20 in #tcp-listener

Download history 15/week @ 2024-09-22 107/week @ 2024-10-20 16/week @ 2024-10-27 13/week @ 2024-11-03 1/week @ 2024-11-10 4/week @ 2024-11-17 173/week @ 2024-11-24 11/week @ 2024-12-01

189 downloads per month
Used in mews

MIT license

305KB
5.5K SLoC

Nio

Nio is an experimental async runtime for Rust.

Nio focuses solely on providing an async runtime, It doesn't include additional utilities like. io, sync, You'll still need to rely on libraries like tokio for everything else.

Example

Add the following dependency to your Cargo.toml:

[dependencies]
nio = "0.0.1"

Here is a basic echo server example:

use nio::net::TcpListener;
use std::io;
use tokio::io::{AsyncReadExt, AsyncWriteExt};

#[nio::main]
async fn main() -> io::Result<()> {
    let listener = TcpListener::bind("127.0.0.1:8080").await?;
    println!("{listener:#?}");
    
    loop {
        let (mut stream, addr) = listener.accept().await?;
        println!("[INCOMING] {addr:?}");

        nio::spawn(async move {
            let mut buf = vec![0; 1024];
            while let Ok(n) = stream.read(&mut buf).await {
                stream.write(&buf[..n]).await.unwrap();
            }
        });
    }
}

Dependencies

~4–14MB
~170K SLoC