Datastar Rust SDK
An implementation of the Datastar SDK in Rust with framework integration for Axum, Rocket, and Warp.
Rust web frameworks own SSE stream lifecycle and backpressure, so this SDK
intentionally returns framework-native events instead of providing a
ServerSentEventGenerator.
Rama has its own SDK implementation defined as a Rama module for Datastar as can be seen in action in this example.
Usage
Runnable examples for every supported framework can be found in
examples.
Long-lived streams
A long-lived SSE handler can receive updates from any number of application
tasks. Publish server-side state changes through channels such as
tokio::sync::watch or tokio::sync::broadcast, then wait on all receivers in
the handler with tokio::select!. Requests that change state only need to
publish an update; the existing SSE response remains open and sends the
corresponding Datastar event.
The axum-watch example demonstrates three
independent watch channels feeding one SSE response. The
rocket-hello-channel example shows the
same basic pattern with Rocket.