2 releases

0.1.1 Dec 31, 2020
0.1.0 Dec 29, 2020

#428 in Asynchronous


Used in safina

Apache-2.0

130KB
2K SLoC

safina-net

crates.io version license: Apache 2.0 unsafe forbidden pipeline status

This is a safe Rust library for network communication.

It is part of safina, a safe async runtime.

Features

  • forbid(unsafe_code)
  • Depends only on std
  • Good test coverage (87%)
  • Works with safina-executor or any async executor

Limitations

  • Allocates
  • Unoptimized

Documentation

https://docs.rs/safina-net

Examples

let bind_addr =
    std::net::SocketAddr::from(([127, 0, 0, 1], 0));
let mut listener =
    safina_net::TcpListener::bind(&bind_addr)
    .unwrap();
let addr = listener.inner().local_addr().unwrap();
println!("{}", &addr);

let executor = safina_executor::Executor::new(1, 1);
executor.spawn(async move {
    let mut tcp_stream =
        safina_net::TcpStream::connect(addr)
        .await
        .unwrap();
    let mut buf = String::new();
    tcp_stream.read_to_string(&mut buf).await.unwrap();
    println!("read {:?}", buf);
});

let (mut tcp_stream, _addr)
    = listener.accept().await.unwrap();
tcp_stream.write_all(b"response").await.unwrap();
println!("wrote response");

For complete examples, see the integration tests in tests/.

Alternatives

  • async-net
    • Dependencies are full of unsafe
  • async-io
    • Full of unsafe
  • tokio
    • Very popular
    • Fast
    • Internally incredibly complicated
    • Full of unsafe
  • tcp-stream
    • Blocks async executor threads
    • Contains a little unsafe code

Changelog

  • v0.1.1
    • Add methods to TcpStream: peek, read_vectored, flush, and write_vectored.
    • Support Windows
  • v0.1.0 - First published version

TO DO

  • DONE - Implement TcpListener and TcpStream with tests & docs
  • DONE - Publish on crates.io
  • Add additional crates with adapters to popular async io traits, like safina-net-tokio, safina-net-futures, etc.

Release Process

  1. Edit Cargo.toml and bump version number.
  2. Run ./release.sh

License: Apache-2.0

Dependencies