pub trait OrderedFuture {
    type Ordering: Ord;
    type Output;

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

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

A Future that produces an item with an associated ordering.

This is equivalent to an OrderedStream that always produces exactly one item. This trait is not very useful on its own; see FromFuture to convert it to a stream.

It is valid to implement both Future and OrderedFuture on the same type. In this case, unless otherwise documented by the implementing type, neither poll function should be invoked after either returns an output value.

Required Associated Types§

Required Methods§

source

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

Attempt to pull out the value of this future, registering the current task for wakeup if needed, and returning None if it is known that the future will not produce a value ordered before the given point.

Return value

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

  • If before was None, Poll::Pending means that this future’s 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 future’s value is not ready and that it is not yet known if the value will be 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(Some(Data)) means that the future has successfully terminated. The returned ordering value may be greater than the value passed to before. The poll_before function should not be invoked again.

  • Poll::Ready(None) means that this future will not produce an ordering token less than the given token. It is an error to return None if before was None.

Provided Methods§

source

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

The minimum value of the ordering of the item.

See OrderedStream::position_hint for details.

Implementors§