pub trait OrderedStream {
    type Ordering: Ord;
    type Data;

    // Required method
    fn poll_next_before(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>,
        before: Option<&Self::Ordering>
    ) -> Poll<PollResult<Self::Ordering, Self::Data>>;

    // Provided methods
    fn position_hint(&self) -> Option<MaybeBorrowed<'_, Self::Ordering>> { ... }
    fn size_hint(&self) -> (usize, Option<usize>) { ... }
}
Expand description

A stream that produces items that are ordered according to some token.

The main advantage of this trait over the standard Stream trait is the ability to implement a join function that does not either block until both source streams produce an item or contain a race condition when rejoining streams that originated from a common well-ordered source.

Required Associated Types§

source

type Ordering: Ord

The type ordered by this stream.

Each stream must produce values that are in ascending order according to this function, although there is no requirement that the values be strictly ascending.

source

type Data

The unordered data carried by this stream

This is split from the Ordering type to allow specifying a smaller or cheaper-to-generate type as the ordering key. This is especially useful if you generate values to pass in to before.

Required Methods§

source

fn poll_next_before( self: Pin<&mut Self>, cx: &mut Context<'_>, before: Option<&Self::Ordering> ) -> Poll<PollResult<Self::Ordering, Self::Data>>

Attempt to pull out the next value of this stream, registering the current task for wakeup if needed, and returning NoneBefore if it is known that the stream will not produce any more values ordered before the given point.

Return value

There are several possible return values, each indicating a distinct stream state depending on the value passed in before:

  • If before was None, Poll::Pending means that this stream’s next value is not ready yet. Implementations will ensure that the current task is notified when the next value may be ready.

  • If before was Some, Poll::Pending means that this stream’s next value is not ready and that it is not yet known if the stream will produce a value ordered prior to the given ordering value. Implementations will ensure that the current task is notified when either the next value is ready or once it is known that no such value will be produced.

  • Poll::Ready(PollResult::Item) means that the stream has successfully produced an item. The stream may produce further values on subsequent poll_next_before calls. The returned ordering value must not be less than any prior ordering value returned by this stream. The returned ordering value may be greater than the value passed to before.

  • Poll::Ready(PollResult::Terminated) means that the stream has terminated, and poll_next_before should not be invoked again.

  • Poll::Ready(PollResult::NoneBefore) means that the stream will not produce any further ordering tokens less than the given token. Subsequent poll_next_before calls may still produce additional items, but their tokens will be greater than or equal to the given token. It does not make sense to return this value if before was None.

Provided Methods§

source

fn position_hint(&self) -> Option<MaybeBorrowed<'_, Self::Ordering>>

The minimum value of the ordering for any future items.

If this does not return None, the returned ordering must be less than or equal to the ordering of any future item returned from Self::poll_next_before. This value should (but is not required to) be greater than or equal to the ordering of the most recent item returned.

source

fn size_hint(&self) -> (usize, Option<usize>)

Returns the bounds on the remaining length of the stream.

Implementations on Foreign Types§

source§

impl<P> OrderedStream for Pin<P>where P: DerefMut + Unpin, P::Target: OrderedStream,

§

type Data = <<P as Deref>::Target as OrderedStream>::Data

§

type Ordering = <<P as Deref>::Target as OrderedStream>::Ordering

source§

fn poll_next_before( self: Pin<&mut Self>, cx: &mut Context<'_>, before: Option<&Self::Ordering> ) -> Poll<PollResult<Self::Ordering, Self::Data>>

source§

fn position_hint(&self) -> Option<MaybeBorrowed<'_, Self::Ordering>>

source§

fn size_hint(&self) -> (usize, Option<usize>)

source§

impl<S> OrderedStream for Option<S>where S: OrderedStream,

§

type Data = <S as OrderedStream>::Data

§

type Ordering = <S as OrderedStream>::Ordering

source§

fn poll_next_before( self: Pin<&mut Self>, cx: &mut Context<'_>, before: Option<&Self::Ordering> ) -> Poll<PollResult<Self::Ordering, Self::Data>>

source§

fn position_hint(&self) -> Option<MaybeBorrowed<'_, Self::Ordering>>

source§

fn size_hint(&self) -> (usize, Option<usize>)

Implementors§

source§

impl<A, B> OrderedStream for Join<A, B>where A: OrderedStream, B: OrderedStream<Data = A::Data, Ordering = A::Ordering>,

source§

impl<C, S> OrderedStream for JoinMultiple<C>where for<'a> &'a mut C: IntoIterator<Item = &'a mut Peekable<S>>, S: OrderedStream + Unpin, S::Ordering: Clone,

source§

impl<C, S> OrderedStream for JoinMultiplePin<C>where for<'a> Pin<&'a mut C>: IntoIterator<Item = Pin<&'a mut Peekable<S>>>, S: OrderedStream, S::Ordering: Clone,

source§

impl<F: OrderedFuture> OrderedStream for FromFuture<F>

source§

impl<S> OrderedStream for FromSortedStream<S>where S: Stream, S::Item: Ord,

§

type Data = ()

§

type Ordering = <S as Stream>::Item

source§

impl<S, F> OrderedStream for Filter<S, F>where S: OrderedStream, F: FnMut(&S::Data) -> bool,

source§

impl<S, F, Fut> OrderedStream for Then<S, F, Fut>where S: OrderedStream, F: FnMut(S::Data) -> Fut, Fut: Future,

§

type Data = <Fut as Future>::Output

§

type Ordering = <S as OrderedStream>::Ordering

source§

impl<S, F, Ordering, Data> OrderedStream for FromStream<S, F, Ordering>where S: Stream, F: FnMut(S::Item) -> (Ordering, Data), Ordering: Ord + Clone,

§

type Data = Data

§

type Ordering = Ordering

source§

impl<S, F, Ordering, Data> OrderedStream for FromStreamDirect<S, F>where S: Stream, F: FnMut(S::Item) -> (Ordering, Data), Ordering: Ord,

§

type Data = Data

§

type Ordering = Ordering

source§

impl<S, F, R> OrderedStream for FilterMap<S, F>where S: OrderedStream, F: FnMut(S::Data) -> Option<R>,

§

type Data = R

§

type Ordering = <S as OrderedStream>::Ordering

source§

impl<S, F, R> OrderedStream for Map<S, F>where S: OrderedStream, F: FnMut(S::Data) -> R,

§

type Data = R

§

type Ordering = <S as OrderedStream>::Ordering

source§

impl<S, F, R> OrderedStream for MapItem<S, F>where S: OrderedStream, F: FnMut(&S::Ordering, S::Data) -> R,

§

type Data = R

§

type Ordering = <S as OrderedStream>::Ordering

source§

impl<S, MapInto, MapFrom, NewOrdering, NewData> OrderedStream for MapOrdering<S, MapInto, MapFrom>where S: OrderedStream, MapInto: FnMut(S::Ordering, S::Data) -> (NewOrdering, NewData), MapFrom: FnMut(&NewOrdering) -> Option<S::Ordering>, NewOrdering: Ord,

§

type Data = NewData

§

type Ordering = NewOrdering

source§

impl<S: OrderedStream> OrderedStream for Peekable<S>