Struct completion::stream::Peekable[][src]

pub struct Peekable<S: CompletionStream> { /* fields omitted */ }

Implementations

impl<S: CompletionStream> Peekable<S>[src]

#[must_use]pub fn peek(self: Pin<&mut Self>) -> Peek<'_, S>

Notable traits for Peek<'a, S>

impl<'a, S> Future for Peek<'a, S> where
    S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>, 
type Output = Self::Output;
[src]

Peek the next value in the stream.

Cancellation

If the returned future is cancelled and the next value in the stream has not been peeked yet, the entire stream is cancelled, otherwise nothing happens.

Examples

use completion::{CompletionStreamExt, StreamExt};
use futures_lite::{stream, pin};

let stream = stream::once(5).into_completion().peekable();
pin!(stream);

assert_eq!(stream.as_mut().peek().await, Some(&5));
assert_eq!(stream.as_mut().peek().await, Some(&5));
assert_eq!(stream.next().await, Some(5));
assert_eq!(stream.as_mut().peek().await, None);
assert_eq!(stream.next().await, None);

#[must_use]pub fn peek_unpin(&mut self) -> Peek<'_, S>

Notable traits for Peek<'a, S>

impl<'a, S> Future for Peek<'a, S> where
    S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>, 
type Output = Self::Output;
where
    Self: Unpin
[src]

Peek the next value in the stream if the underlying type implements Unpin.

stream.peek_unpin() is equivalent to Pin::new(&mut stream).peek(). See peek for more information.

Examples

use completion::{CompletionStreamExt, StreamExt};
use futures_lite::stream;

let mut stream = stream::once(8).into_completion().peekable();

assert_eq!(stream.peek_unpin().await, Some(&8));
assert_eq!(stream.peek_unpin().await, Some(&8));
assert_eq!(stream.next().await, Some(8));
assert_eq!(stream.peek_unpin().await, None);
assert_eq!(stream.next().await, None);

pub unsafe fn poll_peek(
    self: Pin<&mut Self>,
    cx: &mut Context<'_>
) -> Poll<Option<&S::Item>>
[src]

Attempt to peek the next value in the stream.

This function is quite low level, use peek or peek_unpin for a higher-level equivalent.

Safety

See CompletionStream::poll_next.

pub unsafe fn poll_peek_cancel(
    self: Pin<&mut Self>,
    cx: &mut Context<'_>
) -> Poll<()>
[src]

Attempt to cancel peeking the next value in the stream.

This will cancel the underlying stream if the next value in the stream has not already been peeked.

This function is quite low level, use peek or peek_unpin for a higher-level equivalent.

Safety

See CompletionStream::poll_cancel.

Trait Implementations

impl<S: Clone + CompletionStream> Clone for Peekable<S> where
    S::Item: Clone
[src]

impl<S: CompletionStream> CompletionStream for Peekable<S>[src]

type Item = S::Item

Values yielded by the stream.

impl<S: Debug + CompletionStream> Debug for Peekable<S> where
    S::Item: Debug
[src]

impl<S> Stream for Peekable<S> where
    S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>, 
[src]

type Item = <S as CompletionStream>::Item

Values yielded by the stream.

impl<'__pin, S: CompletionStream> Unpin for Peekable<S> where
    __Origin<'__pin, S>: Unpin
[src]

Auto Trait Implementations

impl<S> RefUnwindSafe for Peekable<S> where
    S: RefUnwindSafe,
    <S as CompletionStream>::Item: RefUnwindSafe

impl<S> Send for Peekable<S> where
    S: Send,
    <S as CompletionStream>::Item: Send

impl<S> Sync for Peekable<S> where
    S: Sync,
    <S as CompletionStream>::Item: Sync

impl<S> UnwindSafe for Peekable<S> where
    S: UnwindSafe,
    <S as CompletionStream>::Item: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> CompletionStreamExt for T where
    T: CompletionStream + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> StreamExt for T where
    T: Stream
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<S, T, E> TryStream for S where
    S: Stream<Item = Result<T, E>> + ?Sized
[src]

type Ok = T

The type of successful values yielded by this future

type Error = E

The type of failures yielded by this future