Trait PeekableStream

Source
pub trait PeekableStream: Stream {
    // Required method
    fn poll_peek_mut(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>,
    ) -> Poll<Option<&mut <Self as Stream>::Item>>;

    // Provided method
    fn poll_peek(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>,
    ) -> Poll<Option<&<Self as Stream>::Item>> { ... }
}
Expand description

A stream that provides the ability to peek at the next available item.

This provides an alternative to interfaces and data structure that would otherwise want a [futures::stream::Peekable<S>], which can potentially avoid multiple layers of buffering where one would do.

§Tasks, waking, and calling context

These methods should be called by the task that is reading from the stream. If they are called by another task, the reading task would miss notifications.

Required Methods§

Source

fn poll_peek_mut( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Option<&mut <Self as Stream>::Item>>

Poll for an item to be ready, and then inspect it.

Equivalent to [futures::stream::Peekable::poll_peek_mut].

Guarantees that a returned Ready result is stable (See “Stability” in crate::peekable_stream).

Should be called only by the task that is reading the stream (see “Tasks …” in PeekableStream).

Provided Methods§

Source

fn poll_peek( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Option<&<Self as Stream>::Item>>

Poll for an item to be ready, and then inspect it.

Equivalent to [futures::stream::Peekable::poll_peek].

Guarantees that a returned Ready result is stable (See “Stability …” in crate::peekable_stream).

Should be called only by the task that is reading the stream (see “Tasks …” in PeekableStream).

Implementations on Foreign Types§

Source§

impl<S> PeekableStream for Peekable<S>
where S: Stream,

Source§

fn poll_peek( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Option<&<Self as Stream>::Item>>

Source§

fn poll_peek_mut( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Option<&mut <Self as Stream>::Item>>

Implementors§