Skip to main content

DecodedStreamExt

Trait DecodedStreamExt 

Source
pub trait DecodedStreamExt<I, R>: Stream<Item = Result<I, R>> + Sized
where I: RawItem,
{ // Provided methods fn decoded<E, C>( self, codec: C, ) -> impl Stream<Item = Result<I::Typed<E>, DecodeStreamError<R, C::Error>>> + Send where C: OwningCodec<E>, E: Send + 'static, I: Send + 'static, R: Send + 'static, Self: Send { ... } fn for_each_decoded<E, C, F, H>( self, codec: C, f: F, ) -> impl Future<Output = Result<(), FoldDecodedError<R, C::Error, H>>> where E: ?Sized, C: Decode<E>, F: for<'a> FnMut(Decoded<<C as Decode<E>>::Output<'a>>) -> Result<(), H> { ... } }
Expand description

Adds a typed, codec-reusing view over any stream of raw envelope items.

Covers Subscription, read_stream, and read_all.

Provided Methods§

Source

fn decoded<E, C>( self, codec: C, ) -> impl Stream<Item = Result<I::Typed<E>, DecodeStreamError<R, C::Error>>> + Send
where C: OwningCodec<E>, E: Send + 'static, I: Send + 'static, R: Send + 'static, Self: Send,

Decode each item with codec, reusing the codec configured elsewhere.

Owning codecs only — the for<'a> Output<'a> = E bound is unsatisfiable for a zero-copy codec (whose Output borrows the envelope), so the compiler steers zero-copy consumers to for_each_decoded. Per-stream items become Decoded<E>; $all items become (AllPosition, StreamKey, Decoded<E>) (both tags are preserved beside the box).

Source

fn for_each_decoded<E, C, F, H>( self, codec: C, f: F, ) -> impl Future<Output = Result<(), FoldDecodedError<R, C::Error, H>>>
where E: ?Sized, C: Decode<E>, F: for<'a> FnMut(Decoded<<C as Decode<E>>::Output<'a>>) -> Result<(), H>,

Fold each decoded event by handing your closure the borrowed window — works for owning and zero-copy codecs, because the window lives only for the call and never escapes (internal iteration; no lending stream). This is the path a zero-copy codec (rkyv, bytemuck) must take: its Output borrows the envelope and so cannot be carried away by decoded’s stream.

f receives a Decoded<Output<'a>> valid only for that call. On a never-ending Subscription this runs until the first Err; over a finite read_stream it runs to completion.

The closure argument is the concrete Decoded<Output<'a>> — the event view plus its per-stream version and metadata. It is deliberately not the I::Typed<_> shape decoded yields: a bare closure cannot be inferred higher-ranked over a lifetime hidden behind the I::Typed<_> associated-type projection (rustc “implementation of FnMut is not general enough”), so a concrete outer constructor is required for the zero-copy path to type-check. Consequently, over an $all stream neither the AllPosition tag nor the StreamKey is surfaced to f (the per-stream Decoded::version still is) — a positioned or routed $all consumer must either use decoded (owning codecs), or fold the raw subscribe_all stream directly, calling codec.decode(&env) per item (zero-copy; both tags ride beside the envelope on the raw tuple).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<St, I, R> DecodedStreamExt<I, R> for St
where St: Stream<Item = Result<I, R>>, I: RawItem,