pub trait SseStreamExt<T, E>: Stream<Item = Result<T, E>> + Sized{
// Provided method
fn cast_events<F>(
self,
f: F,
) -> impl Stream<Item = Result<Event, Error>> + Send
where F: FnMut(T) -> Result<Event, Error> + Send,
T: Send,
E: Send,
Self: Send { ... }
}Expand description
Extension trait for converting streams into SSE event streams.
Operates on streams of Result<T, E> — errors pass through unchanged,
and the conversion closure only operates on Ok values.
§Usage
Import the trait and call cast_events on any compatible stream:
use modo::sse::{Broadcaster, Event, SseConfig, SseStreamExt};
let bc: Broadcaster<String, Item> = Broadcaster::new(64, SseConfig::default());
let key = "topic".to_string();
let stream = bc.subscribe(&key).cast_events(|item| {
Event::new(modo::id::short(), "update")?.json(&item)
});Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.