async-stream
Build asynchronous streams in Rust using async/await notation instead of hand-written state machines
Repository Health
Technical Analysis
async-stream is a Tokio-project crate that provides stream! and try_stream! procedural macros, letting Rust code write asynchronous streams using ordinary async/await and yield syntax instead of manually implementing the Stream trait’s poll_next state machine by hand.
The macros expand into an anonymous type implementing futures_core::Stream (Item = T for stream!, Item = Result<T, Error> for try_stream!, which additionally supports ? for early-return error propagation), and the crate works entirely on stable Rust with no unstable-feature requirements.
What You Get
- The
stream!macro for defining aStream<Item = T>using async/await andyieldsyntax - The
try_stream!macro for fallible streams (Item = Result<T, Error>) with?-operator error propagation - Full compatibility with the
futuresecosystem (futures_core::Stream, combinators fromfutures_util) - Zero unstable-feature requirements — works on stable Rust as of edition 2021, rust-version 1.65+
- A companion
async-stream-implproc-macro crate that does the actual macro expansion
Common Use Cases
- Implementing a custom async iterator/stream over a paginated API response without writing a manual
poll_nextstate machine - Building a streaming parser or line-by-line async reader that yields items incrementally as data arrives
- Wrapping a channel or event source (WebSocket messages, database rows) as a
Streamconsumable byfutures/tokio-streamcombinators - Writing test fixtures that need to emit a scripted sequence of async values over time
Under The Hood
Architecture — The repo is a small Cargo workspace with two crates: async-stream (the public-facing crate, src/lib.rs, async_stream.rs, next.rs, yielder.rs) and async-stream-impl (the actual proc-macro crate that parses the macro body and rewrites yield expressions into calls against a hidden coroutine-like driver). The macro-generated code builds a state machine under the hood using a generator built from an async block plus a side-channel Yielder that captures each yielded value, which next.rs/yielder.rs then thread back through poll_next. Tech Stack — Pure Rust (edition 2021, MSRV 1.65), depending only on futures-core (for the Stream trait) and pin-project-lite (for safe pinning), with futures-util, tokio, tokio-test, rustversion, and trybuild as dev-dependencies for testing macro-expansion errors and stream behavior. Code Quality — The test suite includes 12+ integration test files under async-stream/tests/, including trybuild-based compile-fail tests that assert the macro produces sensible error messages for misuse (e.g. yield outside a stream block); the crate has been stable and essentially feature-complete for a couple of years with no active development but no open correctness issues either. API Design — The macro’s design goal is to make an async stream read like ordinary imperative Rust (a for loop with yield inside stream! { }) rather than requiring Pin/Poll/Context boilerplate, which is a significant developer-experience win for anyone who already understands async fn — the main friction is that pin_mut! (or Box::pin) is still required at the call site since the returned stream is !Unpin.
Used by 18 apps in this directory
Laminar
AI Development · Monitoring
Open-source observability platform purpose-built for AI agents — trace, evaluate, debug, and monitor at scale with SQL access and real-time replay.
ParadeDB
Analytics · Databases · Search
Born out of Y Combinator's S2023 batch, ParadeDB is a Postgres extension that delivers Elasticsearch-quality BM25 search and real-time analytics without a separate search cluster to manage.
QuestDB
Analytics · Databases
A high-performance, open-source time-series database built for financial market data, IoT telemetry, and real-time analytics, combining a zero-GC Java/C++ core with SIMD-accelerated SQL and a WAL-to-Parquet storage engine.
Spacedrive
Collaboration · File Storage
One file manager for all your devices and clouds — powered by a Virtual Distributed File System built in Rust.
Stalwart
Collaboration
All-in-one secure mail and collaboration server covering IMAP, JMAP, SMTP, CalDAV, CardDAV, and WebDAV in a single memory-safe Rust binary.
Tabby
AI Code Assistants
Self-hosted AI coding assistant — run GitHub Copilot-grade code completion on your own hardware with no cloud dependency.
Temps
Analytics · Devops · Monitoring
A self-hosted Rust PaaS that replaces Vercel, Sentry, PostHog, Pingdom, Resend, and E2B with one binary — plus 440+ CLI operations agents like Claude Code can drive directly.
Vibe Kanban
AI Agents · AI Code Assistants · Project Management
A kanban board for planning work and dispatching Claude Code, Codex, Gemini CLI, and eight other coding agents into isolated git worktrees, then reviewing and merging their diffs from one UI.
Volga
Data Engineering
A Rust-based real-time data processing engine for AI/ML feature computation, built on Apache DataFusion and Arrow — positioned as an alternative to Flink, Spark, Chronon, and OpenMLDB with unified streaming, batch, and request-time execution.