Crates.io | wstd |
lib.rs | wstd |
version | 0.4.0 |
source | src |
created_at | 2024-07-26 14:08:37.034147 |
updated_at | 2024-07-29 22:53:48.286668 |
description | An async standard library for Wasm Components and WASI 0.2 |
homepage | |
repository | https://github.com/yoshuawuyts/wstd |
max_upload_size | |
id | 1316131 |
size | 76,968 |
This is a minimal async standard library written exclusively to support Wasm Components. It exists primarily to enable people to write async-based applications in Rust before async-std, smol, or tokio land support for Wasm Components and WASI 0.2. Once those runtimes land support, it is recommended users switch to use those instead.
TCP echo server
use wstd::io;
use wstd::iter::AsyncIterator;
use wstd::net::TcpListener;
use wstd::runtime::block_on;
fn main() -> io::Result<()> {
block_on(|reactor| async move {
let listener = TcpListener::bind(&reactor, "127.0.0.1:8080").await?;
println!("Listening on {}", listener.local_addr()?);
println!("type `nc localhost 8080` to create a TCP client");
let mut incoming = listener.incoming();
while let Some(stream) = incoming.next().await {
let stream = stream?;
println!("Accepted from: {}", stream.peer_addr()?);
io::copy(&stream, &stream).await?;
}
Ok(())
})
}
$ cargo add wstd
This crate uses #![deny(unsafe_code)]
to ensure everything is implemented in
100% Safe Rust.
Want to join us? Check out our "Contributing" guide and take a look at some of these issues: