pub trait UnobtrusivePeekableStream: Stream {
// Required method
fn unobtrusive_peek_mut(
self: Pin<&mut Self>,
) -> Option<&mut <Self as Stream>::Item>;
// Provided method
fn unobtrusive_peek(self: Pin<&mut Self>) -> Option<&<Self as Stream>::Item> { ... }
}
Expand description
A stream that supports peeking without perturbing any registered waker.
§Tasks, waking, and calling context
These functions do not register the current task to be woken when an item becomes available on the stream, and ensure that the most recent task that was already registered remains so (or is woken if there was an item ready).
Therefore, avoiding calling (only) these functions from the task that is reading from the stream, since they will not cause the current task to be woken when an item arrives.
Conversely, you may call these function in other tasks, without disturbing the task which is waiting for input.
Required Methods§
Sourcefn unobtrusive_peek_mut(
self: Pin<&mut Self>,
) -> Option<&mut <Self as Stream>::Item>
fn unobtrusive_peek_mut( self: Pin<&mut Self>, ) -> Option<&mut <Self as Stream>::Item>
Peek at the next available value, while not losing a previously registered waker.
Guarantees that a returned Some
result is stable (See “Stability” in
crate::peekable_stream
).
Does not register the current task to be notified when an item becomes
available (see “Tasks …” in UnobtrusivePeekableStream
).
The caller of unobtrusive_peek_mut
can’t distinguish between a pending and terminated stream.
Provided Methods§
Sourcefn unobtrusive_peek(self: Pin<&mut Self>) -> Option<&<Self as Stream>::Item>
fn unobtrusive_peek(self: Pin<&mut Self>) -> Option<&<Self as Stream>::Item>
Peek at the next available value, while not losing a previously registered waker.
Guarantees that a returned Some
result is stable (See “Stability” in
crate::peekable_stream
).
Does not register the current task to be notified when an item becomes
available (see “Tasks …” in UnobtrusivePeekableStream
).
The caller of unobtrusive_peek
can’t distinguish between a pending and terminated stream.