Crate agnostic_net

Crate agnostic_net 

Source
Expand description

Agnostic Network

Agnostic abstraction layer of std::net for any async runtime.

github LoC Build codecov

docs.rs crates.io crates.io license

§Introduction

agnostic-net provides runtime-agnostic abstractions for TCP and UDP networking. Write your network code once and run it with tokio, or smol - without any code changes.

§Key Features

  • TCP Support: Async TCP listeners and streams
  • UDP Support: Async UDP sockets
  • Cross-Platform: Works on Unix, Windows, and other platforms
  • Runtime Agnostic: Seamlessly switch between tokio, and smol
  • Zero-Cost: Compiles to runtime-specific code
  • Familiar API: Similar to std::net but async

§Supported Runtimes

  • tokio - Enable with features = ["tokio"]
  • smol - Enable with features = ["smol"]

§Installation

[dependencies]
agnostic-net = "0.3"
  • tokio

    agnostic-net = { version = "0.3", features = ["tokio"] }
  • smol

    agnostic-net = { version = "0.3", features = ["smol"] }

§Platform Support

agnostic-net works on all major platforms:

  • Unix/Linux: Full support via rustix
  • Windows: Full support via windows-sys and socket2
  • macOS: Full support
  • BSD: Full support

§Feature Flags

  • std (default): Standard library support
  • tokio: Tokio runtime support
  • tokio-io: Tokio I/O trait implementations
  • smol: Smol runtime support

§Performance Considerations

  • Zero-cost abstractions: Compiles to runtime-specific code
  • No runtime overhead: Direct delegation to underlying runtime
  • Efficient I/O: Uses platform-specific optimizations
§License

agnostic-net is under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE, LICENSE-MIT for details.

Copyright (c) 2025 Al Liu.

Re-exports§

pub use agnostic_lite as runtime;
pub use agnostic_io as io;

Modules§

os
Operating system specific types and traits.

Traits§

Net
An abstraction layer for the async runtime’s network.
OwnedReadHalf
The abstraction of a owned read half of a TcpStream.
OwnedWriteHalf
The abstraction of a owned write half of a TcpStream.
ReuniteError
Error indicating that two halves were not from the same socket, and thus could not be reunited.
TcpListener
An abstraction layer for TCP listener.
TcpStream
The abstraction of a TCP stream.
ToSocketAddrs
Converts or resolves without blocking base on your async runtime to one or more SocketAddr values.
UdpSocket
The abstraction of a UDP socket.