CodeVetter · Repo Unpack · Extension points
tokio-rs/tokio
The principal extension mechanism is Rust trait composition, supplemented by builders and adapters. Custom transports implement async I/O traits; custom protocols implement codec traits. Runtime hooks permit instrumentation, while stream wrappers and maps integrate additional event sources. Feature and platform gates define extension boundaries, and some interfaces are deliberately sealed or unstable.
- Custom transports implement AsyncRead::poll_read and AsyncWrite::poll_write/poll_flush, including arranging waker notifications when returning Pending.
- Protocol codecs implement Decoder with Item/Error and Encoder<Item>; Decoder provides EOF handling, while Encoder writes into the framing layer's BytesMut buffer.
- Builder instrumentation stores Send + Sync thread-start callbacks; on_before_task_poll receives TaskMeta and is additionally gated by tokio_unstable.
- TcpStream::from_std bridges externally created sockets into Mio/PollEvented; callers must provide nonblocking sockets and an entered runtime with I/O enabled.
- ReceiverStream adapts an mpsc Receiver by forwarding poll_next to poll_recv; StreamMap accepts replacement streams by key and emits keyed Stream items.
- Command::spawn_with permits custom standard-process spawning while reusing child wrapping; the implementation notes this API is behind tokio_unstable.
- New public capability wiring belongs in crate feature tables and gated module exports; tokio-util independently maps features to Tokio dependencies and utility modules.
- ToSocketAddrs inherits a sealed private trait, so address resolution is not an open downstream implementation hook; inspected string implementations choose immediate parsing or blocking DNS.