Skip to main content

StreamExt

Trait StreamExt 

Source
pub trait StreamExt: Stream + Sized {
    // Required methods
    fn until_overridden_by<Other: Stream<Item = Self::Item>>(
        self,
        other: Other,
    ) -> UntilOverriddenBy<Self, Other>;
    fn breaker(self) -> Breaker<Self>;
    fn sync(
        self,
        capacity: NonZero<usize>,
    ) -> SyncStream<Result<Self::Item, Truncated>>
       where Self: 'static,
             Self::Item: Send + 'static;
}
Expand description

Extension trait for Streams

Required Methods§

Source

fn until_overridden_by<Other: Stream<Item = Self::Item>>( self, other: Other, ) -> UntilOverriddenBy<Self, Other>

Yields items from the current, first, stream until an item from the other, second, stream becomes available. At that point the first stream is dropped, and only items from the second stream are yielded.

Source

fn breaker(self) -> Breaker<Self>

Like futures::stream::Fuse, but can be ‘tripped’ to cut the stream short.

Source

fn sync( self, capacity: NonZero<usize>, ) -> SyncStream<Result<Self::Item, Truncated>>
where Self: 'static, Self::Item: Send + 'static,

Relays this stream over a channel so that a !Send stream — e.g. one tied to a single-threaded runtime — can be consumed from anywhere a Send + Sync stream is required.

A background pump task forwards each item over the channel; this method spawns it with tokio::task::spawn_local, so it must be called from within a tokio::task::LocalSet. capacity bounds how many items may buffer ahead of a slow consumer.

Each source item is yielded as Ok. If the pump or source is dropped before the source is exhausted (e.g. its runtime is torn down mid-relay), the final item is Err(Truncated) — so a stream cut short can never be mistaken for a clean end. See also SyncStream::new, which hands back the pump for you to drive yourself.

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.

Implementors§

Source§

impl<S: Stream> StreamExt for S