Crates.io | nio |
lib.rs | nio |
version | 0.0.1 |
source | src |
created_at | 2024-10-24 20:59:42.555591 |
updated_at | 2024-11-24 15:30:36.592836 |
description | An experimental async runtime for Rust |
homepage | |
repository | |
max_upload_size | |
id | 1421781 |
size | 381 |
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.
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();
}
});
}
}