Installation
A service depends on one crate, ruststream, whose surface is enabled by additive cargo features.
It re-exports the crates RustStream is built from, so a service never names them. Add it to your
Cargo.toml:
[dependencies]
ruststream = { version = "0.8", features = ["macros", "memory", "json"] }
serde = { version = "1", features = ["derive"] }
serde is a direct dependency of your service because your message types derive Deserialize /
Serialize.
RustStream targets edition 2024 and a minimum supported Rust version of 1.95. Set
edition = "2024" in your Cargo.toml.
A broker crate may need a newer Rust than the core when its client library does. The broker
crate's own rust-version field states the exact minimum version.
Features
The core traits, the Router, middleware and message dispatch are always compiled. The application
object comes with a runner feature, and everything else is an additive feature you enable when you
need it.
| Feature | Pulls in | What it gives you |
|---|---|---|
tokio (default) | tokio | the tokio runner: RustStream, the application object that runs on tokio |
compio | compio | the compio runner, one runtime per core, on io_uring where the kernel has it |
embassy | embassy | the embassy runner for firmware: EmbeddedApp |
tracing, log, defmt | the logging crate of the same name | the loggers an app selects with .logger(..); the tokio runner turns tracing on |
json (default) | serde_json | JsonCodec |
msgpack | rmp-serde | MsgpackCodec |
cbor | ciborium | CborCodec |
memory | - | MemoryBroker, the in-memory reference broker |
macros | ruststream-macros | #[subscriber], #[ruststream::app], and the derives (Outgoing, OutSlot, OutMessages, Deserialized, Serialized, FromRef, MessageInfo) |
asyncapi | schemars, serde_norway | AsyncAPI generation and the HTML viewer |
metrics | prometheus | Prometheus middleware and exporter |
logging | tracing-subscriber | ruststream::logging, a colored console logger (Logging) |
otel | opentelemetry, opentelemetry-otlp | OTLP export for traces and metrics, and W3C trace-context propagation (OpenTelemetry) |
testing | inventory | TestApp and the assertion builders (Testing) |
conformance | inventory | the broker-author conformance harness |
cli | clap, anyhow | the ruststream binary |
You can enable several codecs at once (see Codecs). To drop the bundled JSON codec (for example in a broker crate that needs only the traits and the runtime), disable the default features and name the runtime:
[dependencies]
ruststream = { version = "0.8", default-features = false, features = ["tokio"] }
Without the standard library
A broker crate for a device depends on the facade too. With the default features off,
ruststream builds with #![no_std] and keeps headers and payloads in storage of a fixed size:
[dependencies]
ruststream = { version = "0.8", default-features = false }
With the alloc feature it keeps them on the heap:
[dependencies]
ruststream = { version = "0.8", default-features = false, features = ["alloc"] }
The standard library comes with the runtimes that need it, tokio and compio. They and the
codecs that need a heap turn alloc on themselves.
The CLI
The ruststream binary ships with the crate behind the cli cargo feature. It runs cargo with
the framework's subcommands (run, asyncapi gen); installation and commands are in the
runtime::cli module. cargo generate scaffolds a new project from a template, covered in
the quick start.
Concrete brokers
The memory broker is built into the crate and needs no external service. To reach a broker outside
the process, depend on that broker's crate; it re-exports from ruststream everything it needs.
Each broker has its own version and its own release cycle, so the exact dependency line, with the
current version and the testing feature for handler tests, is in the broker's own documentation.
The same documentation describes the broker's connection options and its capabilities.
The available brokers are listed under Brokers; the link there leads to each
broker's documentation and its installation instructions. To write your own broker, see
the Broker trait.