async_foundation/lib.rs
1#![recursion_limit = "256"]
2//! Foundational async primitives for Rust – timers, networking utilities, and common async building blocks.
3//!
4//! This crate is **runtime-agnostic**: it focuses on low-level primitives that can be
5//! plugged into your own executor or existing async ecosystem.
6//!
7//! # Modules
8//!
9//! - [`timer`] – high-level timer abstraction for scheduling waits and handling many
10//! concurrent timers efficiently.
11//! - [`net`] – async wrappers around non-async `mio` types (`TcpStream`, `UdpSocket`,
12//! event listener, timeouts). Enabled by the `net` feature.
13//! - [`common`] – utilities such as [`common::ready_future::ReadyFuture`] and
14//! [`common::ready_observable::ReadyObservable`] for composing async workflows.
15//!
16//! # Quick start
17//!
18//! Basic timer usage:
19//!
20//! ```no_run
21//! use async_foundation::timer::timer::Timer;
22//! use futures::executor::block_on;
23//! use std::time::Duration;
24//!
25//! let mut timer = Timer::new();
26//! block_on(async {
27//! // Wait for 100ms
28//! timer.wait(Duration::from_millis(100)).await;
29//! });
30//! ```
31//!
32//! TCP client using the async `TcpStream` wrapper:
33//!
34//! ```no_run
35//! use async_foundation::net::tcp_stream::TcpStream;
36//! use futures::executor::block_on;
37//! use futures::{AsyncReadExt, AsyncWriteExt};
38//!
39//! block_on(async {
40//! let mut stream = TcpStream::connect("127.0.0.1:8080").unwrap();
41//! stream.write_all(b"ping").await.unwrap();
42//! let mut buf = [0u8; 4];
43//! let _ = stream.read(&mut buf).await.unwrap();
44//! });
45//! ```
46
47pub mod common;
48pub mod net;
49pub mod timer;