futures_concurrency::concurrent_stream

Trait ConcurrentStream

source
pub trait ConcurrentStream {
    type Item;
    type Future: Future<Output = Self::Item>;

    // Required methods
    async fn drive<C>(self, consumer: C) -> C::Output
       where C: Consumer<Self::Item, Self::Future>;
    fn concurrency_limit(&self) -> Option<NonZeroUsize>;

    // Provided methods
    fn size_hint(&self) -> (usize, Option<usize>) { ... }
    fn enumerate(self) -> Enumerate<Self>
       where Self: Sized { ... }
    fn limit(self, limit: Option<NonZeroUsize>) -> Limit<Self>
       where Self: Sized { ... }
    fn take(self, limit: usize) -> Take<Self>
       where Self: Sized { ... }
    fn map<F, FutB, B>(
        self,
        f: F,
    ) -> Map<Self, F, Self::Future, Self::Item, FutB, B>
       where Self: Sized,
             F: Fn(Self::Item) -> FutB + Clone,
             FutB: Future<Output = B> { ... }
    async fn for_each<F, Fut>(self, f: F)
       where Self: Sized,
             F: Fn(Self::Item) -> Fut + Clone,
             Fut: Future<Output = ()> { ... }
    async fn try_for_each<F, Fut, E>(self, f: F) -> Result<(), E>
       where Self: Sized,
             F: Fn(Self::Item) -> Fut + Clone,
             Fut: Future<Output = Result<(), E>> { ... }
    async fn collect<B>(self) -> B
       where B: FromConcurrentStream<Self::Item>,
             Self: Sized { ... }
}
Expand description

Concurrently operate over items in a stream

Required Associated Types§

source

type Item

Which item will we be yielding?

source

type Future: Future<Output = Self::Item>

What’s the type of the future containing our items?

Required Methods§

source

async fn drive<C>(self, consumer: C) -> C::Output
where C: Consumer<Self::Item, Self::Future>,

Internal method used to define the behavior of this concurrent iterator. You should not need to call this directly. This method causes the iterator self to start producing items and to feed them to the consumer consumer one by one.

source

fn concurrency_limit(&self) -> Option<NonZeroUsize>

How much concurrency should we apply?

Provided Methods§

source

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

How many items could we potentially end up returning?

source

fn enumerate(self) -> Enumerate<Self>
where Self: Sized,

Creates a stream which gives the current iteration count as well as the next value.

The value is determined by the moment the future is created, not the moment the future is evaluated.

source

fn limit(self, limit: Option<NonZeroUsize>) -> Limit<Self>
where Self: Sized,

Obtain a simple pass-through adapter.

source

fn take(self, limit: usize) -> Take<Self>
where Self: Sized,

Creates a stream that yields the first n elements, or fewer if the underlying iterator ends sooner.

source

fn map<F, FutB, B>( self, f: F, ) -> Map<Self, F, Self::Future, Self::Item, FutB, B>
where Self: Sized, F: Fn(Self::Item) -> FutB + Clone, FutB: Future<Output = B>,

Convert items from one type into another

source

async fn for_each<F, Fut>(self, f: F)
where Self: Sized, F: Fn(Self::Item) -> Fut + Clone, Fut: Future<Output = ()>,

Iterate over each item concurrently

source

async fn try_for_each<F, Fut, E>(self, f: F) -> Result<(), E>
where Self: Sized, F: Fn(Self::Item) -> Fut + Clone, Fut: Future<Output = Result<(), E>>,

Iterate over each item concurrently, short-circuit on error.

If an error is returned this will cancel all other futures.

source

async fn collect<B>(self) -> B
where B: FromConcurrentStream<Self::Item>, Self: Sized,

Transforms an iterator into a collection.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

source§

impl<CS, F, FutT, T, FutB, B> ConcurrentStream for Map<CS, F, FutT, T, FutB, B>
where CS: ConcurrentStream<Item = T, Future = FutT>, F: Fn(T) -> FutB + Clone, FutT: Future<Output = T>, FutB: Future<Output = B>,

source§

type Future = MapFuture<F, FutT, T, FutB, B>

source§

type Item = B

source§

impl<CS: ConcurrentStream> ConcurrentStream for Enumerate<CS>

source§

type Item = (usize, <CS as ConcurrentStream>::Item)

source§

type Future = EnumerateFuture<<CS as ConcurrentStream>::Future, <CS as ConcurrentStream>::Item>

source§

impl<CS: ConcurrentStream> ConcurrentStream for Limit<CS>

source§

impl<CS: ConcurrentStream> ConcurrentStream for Take<CS>

source§

impl<S> ConcurrentStream for FromStream<S>
where S: Stream,

source§

impl<T> ConcurrentStream for IntoConcurrentStream<T>