Trait completion::stream::CompletionStreamExt [−][src]
Extension trait for CompletionStream
.
Provided methods
unsafe fn poll_next(&mut self, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> where
Self: Unpin,
[src]
Self: Unpin,
A convenience for calling CompletionStream::poll_next
on Unpin
streams.
Safety
Identical to CompletionStream::poll_next
.
unsafe fn poll_cancel(&mut self, cx: &mut Context<'_>) -> Poll<()> where
Self: Unpin,
[src]
Self: Unpin,
A convenience for calling CompletionStream::poll_cancel
on Unpin
streams.
Safety
Identical to CompletionStream::poll_cancel
.
fn must_complete(self) -> MustComplete<Self> where
Self: Sized,
[src]
Self: Sized,
Make sure that the stream will complete. Any requests to cancel the stream through
poll_cancel
will be ignored.
fn next(&mut self) -> Next<'_, Self>ⓘNotable traits for Next<'_, S>
impl<S: Unpin + ?Sized> Future for Next<'_, S> where
S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>, type Output = Option<<S as CompletionStream>::Item>;
where
Self: Unpin,
[src]
Notable traits for Next<'_, S>
impl<S: Unpin + ?Sized> Future for Next<'_, S> where
S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>, type Output = Option<<S as CompletionStream>::Item>;
Self: Unpin,
Get the next item in the stream.
Be aware that if you cancel the returned future, the stream itself will be cancelled and so any further attempts to use it may panic, block forever, or do other unexpected things.
Examples
use completion::{CompletionStreamExt, StreamExt}; use futures_lite::stream; let mut stream = stream::iter(0..3).into_completion(); assert_eq!(stream.next().await, Some(0)); assert_eq!(stream.next().await, Some(1)); assert_eq!(stream.next().await, Some(2)); assert_eq!(stream.next().await, None);
fn count(self) -> Count<Self>ⓘNotable traits for Count<S>
impl<S> Future for Count<S> where
S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>, type Output = usize;
where
Self: Sized,
[src]
Notable traits for Count<S>
impl<S> Future for Count<S> where
S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>, type Output = usize;
Self: Sized,
Count the number of items in the stream.
Examples
use completion::{CompletionStreamExt, StreamExt}; use futures_lite::stream; let stream_1 = stream::iter(3..7).into_completion(); let stream_2 = stream::iter(&[8, 2, 4]).into_completion(); assert_eq!(stream_1.count().await, 4); assert_eq!(stream_2.count().await, 3);
fn last(self) -> Last<Self>ⓘNotable traits for Last<S>
impl<S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>> Future for Last<S> type Output = Option<<S as CompletionStream>::Item>;
where
Self: Sized,
[src]
Notable traits for Last<S>
impl<S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>> Future for Last<S> type Output = Option<<S as CompletionStream>::Item>;
Self: Sized,
Get the last element in the stream.
Examples
use completion::{CompletionStreamExt, StreamExt}; use futures_lite::stream; assert_eq!(stream::iter(3..7).into_completion().last().await, Some(6)); assert_eq!(stream::empty::<String>().into_completion().last().await, None);
fn nth(&mut self, n: usize) -> Nth<'_, Self>ⓘNotable traits for Nth<'_, S>
impl<S: Unpin + ?Sized> Future for Nth<'_, S> where
S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>, type Output = Option<<S as CompletionStream>::Item>;
where
Self: Unpin,
[src]
Notable traits for Nth<'_, S>
impl<S: Unpin + ?Sized> Future for Nth<'_, S> where
S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>, type Output = Option<<S as CompletionStream>::Item>;
Self: Unpin,
Get the nth element in the stream.
Examples
use completion::{CompletionStreamExt, StreamExt}; use futures_lite::stream; assert_eq!(stream::iter(3..7).into_completion().nth(2).await, Some(5)); assert_eq!(stream::iter(3..7).into_completion().nth(10).await, None);
fn step_by(self, step: usize) -> StepBy<Self> where
Self: Sized,
[src]
Self: Sized,
Create a stream starting at the same point, but stepping by the given amount each iteration.
Panics
This will panic if step
is 0
.
Examples
use completion::{CompletionStreamExt, StreamExt}; use futures_lite::stream; let a = [0, 1, 2, 3, 4, 5]; let mut stream = stream::iter(&a).into_completion().step_by(2); assert_eq!(stream.next().await, Some(&0)); assert_eq!(stream.next().await, Some(&2)); assert_eq!(stream.next().await, Some(&4)); assert_eq!(stream.next().await, None);
fn chain<U: CompletionStream<Item = Self::Item>>(
self,
other: U
) -> Chain<Self, U> where
Self: Sized,
[src]
self,
other: U
) -> Chain<Self, U> where
Self: Sized,
Chain this stream with another.
Examples
use completion::{CompletionStreamExt, StreamExt}; use futures_lite::stream; let mut stream = stream::iter(4..6).into_completion() .chain(stream::iter(6..10).into_completion()); assert_eq!(stream.next().await, Some(4)); assert_eq!(stream.next().await, Some(5)); assert_eq!(stream.next().await, Some(6)); assert_eq!(stream.next().await, Some(7)); assert_eq!(stream.next().await, Some(8)); assert_eq!(stream.next().await, Some(9)); assert_eq!(stream.next().await, None);
fn map<T, F: FnMut(Self::Item) -> T>(self, f: F) -> Map<Self, F> where
Self: Sized,
[src]
Self: Sized,
Map this stream’s items with a closure.
Examples
use completion::{CompletionStreamExt, StreamExt}; use futures_lite::stream; let mut stream = stream::iter(0..5).into_completion().map(|x| x * 2 + 4); assert_eq!(stream.next().await, Some(4)); assert_eq!(stream.next().await, Some(6)); assert_eq!(stream.next().await, Some(8)); assert_eq!(stream.next().await, Some(10)); assert_eq!(stream.next().await, Some(12)); assert_eq!(stream.next().await, None);
fn then<F: FnMut(Self::Item) -> Fut, Fut: CompletionFuture>(
self,
f: F
) -> Then<Self, F, Fut> where
Self: Sized,
[src]
self,
f: F
) -> Then<Self, F, Fut> where
Self: Sized,
Map this stream’s items with an asynchronous closure.
Examples
use completion::{CompletionStreamExt, StreamExt, completion_async_move}; use futures_lite::stream; let mut stream = stream::iter(0..5) .into_completion() .then(|x| completion_async_move!(x * 2 + 4)); futures_lite::pin!(stream); assert_eq!(stream.next().await, Some(4)); assert_eq!(stream.next().await, Some(6)); assert_eq!(stream.next().await, Some(8)); assert_eq!(stream.next().await, Some(10)); assert_eq!(stream.next().await, Some(12)); assert_eq!(stream.next().await, None);
fn for_each<F: FnMut(Self::Item)>(self, f: F) -> ForEach<Self, F>ⓘNotable traits for ForEach<S, F>
impl<S, F> Future for ForEach<S, F> where
S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>,
F: FnMut(<S as CompletionStream>::Item), type Output = ();
where
Self: Sized,
[src]
Notable traits for ForEach<S, F>
impl<S, F> Future for ForEach<S, F> where
S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>,
F: FnMut(<S as CompletionStream>::Item), type Output = ();
Self: Sized,
Call a closure on each item the stream.
Examples
use completion::{CompletionStreamExt, StreamExt}; use futures_lite::stream; stream::iter(0..8).into_completion().for_each(|num| println!("{}", num)).await;
fn filter<F>(self, f: F) -> Filter<Self, F> where
F: FnMut(&Self::Item) -> bool,
Self: Sized,
[src]
F: FnMut(&Self::Item) -> bool,
Self: Sized,
Keep the values in the stream for which the predicate resolves to true
.
Examples
use completion::{CompletionStreamExt, StreamExt}; use futures_lite::stream; let mut stream = stream::iter(1..=10).into_completion().filter(|n| n % 3 == 0); assert_eq!(stream.next().await, Some(3)); assert_eq!(stream.next().await, Some(6)); assert_eq!(stream.next().await, Some(9)); assert_eq!(stream.next().await, None);
fn filter_map<T, F>(self, f: F) -> FilterMap<Self, F> where
F: FnMut(Self::Item) -> Option<T>,
Self: Sized,
[src]
F: FnMut(Self::Item) -> Option<T>,
Self: Sized,
Filter and map the items of the stream with a closure.
This will yield any values for which the closure returns Some
and will discard any
values for which the closure returns None
.
Examples
use completion::{CompletionStreamExt, StreamExt}; use futures_lite::stream; let strings = ["5", "!", "2", "NaN", "6", ""]; let stream = stream::iter(&strings).into_completion(); let mut stream = stream.filter_map(|s| s.parse::<i32>().ok()); assert_eq!(stream.next().await, Some(5)); assert_eq!(stream.next().await, Some(2)); assert_eq!(stream.next().await, Some(6)); assert_eq!(stream.next().await, None);
fn enumerate(self) -> Enumerate<Self> where
Self: Sized,
[src]
Self: Sized,
Yield the current iteration count as well as the next value.
The returned stream yields pairs (i, val)
where i
is the current index of iteration and
val
is the value returned by the stream.
Overflow Behaviour
The method does no guarding against overflows, so enumerating more than usize::MAX
elements either produces the wrong result or panics. If debug assertions are enabled, a
panic is guaranteed.
Panics
The returned stream might panic if the to-be-returned index would overflow a usize
.
Examples
use completion::{CompletionStreamExt, StreamExt}; use futures_lite::stream; let string = "Hello"; let mut stream = stream::iter(string.chars()).into_completion().enumerate(); assert_eq!(stream.next().await, Some((0, 'H'))); assert_eq!(stream.next().await, Some((1, 'e'))); assert_eq!(stream.next().await, Some((2, 'l'))); assert_eq!(stream.next().await, Some((3, 'l'))); assert_eq!(stream.next().await, Some((4, 'o'))); assert_eq!(stream.next().await, None);
fn peekable(self) -> Peekable<Self> where
Self: Sized,
[src]
Self: Sized,
Create a stream which can use peek
to look at the next element of the
stream without consuming it.
Note that the underlying stream is still advanced when peek
is called
for the first time after next
; in order to retrieve the next element,
next
is called on the underlying stream, hence any side effects of the
method with occur.
Examples
use completion::{CompletionStreamExt, StreamExt}; use futures_lite::{stream, pin}; let mut stream = stream::iter("Hello!\n".chars()).into_completion().peekable(); let mut s = String::new(); while stream.peek_unpin().await != Some(&'\n') { s.push(stream.next().await.unwrap()); } assert_eq!(s, "Hello!"); assert_eq!(stream.next().await, Some('\n')); assert_eq!(stream.next().await, None);
fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P> where
P: FnMut(&Self::Item) -> bool,
Self: Sized,
[src]
P: FnMut(&Self::Item) -> bool,
Self: Sized,
Skip items while the predicate returns true
.
Examples
use completion::{CompletionStreamExt, StreamExt}; use futures_lite::stream; let stream = stream::iter(" Hello world!".chars()).into_completion(); let text: String = stream.skip_while(char::is_ascii_whitespace).collect().await; assert_eq!(text, "Hello world!");
fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P> where
P: FnMut(&Self::Item) -> bool,
Self: Sized,
[src]
P: FnMut(&Self::Item) -> bool,
Self: Sized,
Take items while the predicate returns true
.
Examples
use completion::{CompletionStreamExt, StreamExt}; use futures_lite::stream; let stream = stream::iter("Hello world!\nFoo bar".chars()).into_completion(); let text: String = stream.take_while(|&c| c != '\n').collect().await; assert_eq!(text, "Hello world!");
fn skip(self, n: usize) -> Skip<Self> where
Self: Sized,
[src]
Self: Sized,
Skip the first n
items in the stream.
Examples
use completion::{CompletionStreamExt, StreamExt}; use futures_lite::stream; let stream = stream::iter(0..10).into_completion(); assert_eq!(stream.skip(5).collect::<Vec<_>>().await, [5, 6, 7, 8, 9]);
fn take(self, n: usize) -> Take<Self> where
Self: Sized,
[src]
Self: Sized,
Takes the first n
items of the stream. All other items will be ignored.
Examples
use completion::{CompletionStreamExt, StreamExt}; use futures_lite::stream; let stream = stream::repeat(19).into_completion(); assert_eq!(stream.take(5).collect::<Vec<_>>().await, [19, 19, 19, 19, 19]);
fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F> where
Self: Sized,
U: CompletionStream,
F: FnMut(Self::Item) -> U,
[src]
Self: Sized,
U: CompletionStream,
F: FnMut(Self::Item) -> U,
Map the stream, flattening nested structure.
.flat_map(f)
is equivalent to .[
map](Self::map)
(f).[
flatten](Self::flatten)
()`.
Examples
use completion::{CompletionStreamExt, StreamExt}; use futures_lite::stream; let s: String = stream::iter(&["alpha", "beta", "gamma"]) .into_completion() .flat_map(|s| stream::iter(s.chars()).into_completion()) .collect() .await; assert_eq!(s, "alphabetagamma");
fn flatten(self) -> Flatten<Self> where
Self: Sized,
Self::Item: CompletionStream,
[src]
Self: Sized,
Self::Item: CompletionStream,
Flatten nested structure in the stream.
This converts a stream of streams to a stream.
Examples
use completion::{CompletionStreamExt, StreamExt}; use futures_lite::stream; let streams = vec![ stream::iter(0..5).into_completion(), stream::iter(5..7).into_completion(), ]; let v: Vec<u8> = stream::iter(streams).into_completion().flatten().collect().await; assert_eq!(v, &[0, 1, 2, 3, 4, 5, 6]);
fn fuse(self) -> Fuse<Self> where
Self: Sized,
[src]
Self: Sized,
Fuse the stream so that it is guaranteed to continue to yield None
when exhausted.
If the stream is cancelled, it is also guaranteed to continue to yield None
.
Examples
use completion::{CompletionStreamExt, StreamExt}; use futures_lite::stream; let mut stream = stream::once(5).into_completion().fuse(); assert_eq!(stream.next().await, Some(5)); assert_eq!(stream.next().await, None); assert_eq!(stream.next().await, None); assert_eq!(stream.next().await, None);
fn inspect<F>(self, f: F) -> Inspect<Self, F> where
Self: Sized,
F: FnMut(&Self::Item),
[src]
Self: Sized,
F: FnMut(&Self::Item),
Do something with each element in the stream, passing the value on.
Examples
use completion::{CompletionStreamExt, StreamExt}; use futures_lite::stream; let sum = stream::iter(0..16) .into_completion() .inspect(|x| println!("about to filter: {}", x)) .filter(|x| x % 2 == 0) .inspect(|x| println!("made it through filter: {}", x)) .fold(0_u32, |sum, i| sum + i) .await; assert_eq!(sum, 56);
fn collect<C: FromCompletionStream<Self::Item>>(self) -> Collect<Self, C>ⓘNotable traits for Collect<S, C>
impl<S, C> Future for Collect<S, C> where
S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>,
C: FromCompletionStream<<S as CompletionStream>::Item>, type Output = C;
where
Self: Sized,
[src]
Notable traits for Collect<S, C>
impl<S, C> Future for Collect<S, C> where
S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>,
C: FromCompletionStream<<S as CompletionStream>::Item>, type Output = C;
Self: Sized,
Collect all the items in the stream into a collection.
Examples
use completion::{CompletionStreamExt, completion_stream}; let stream = completion_stream! { for i in 0..5 { yield i; } }; let items: Vec<_> = stream.collect().await; assert_eq!(items, [0, 1, 2, 3, 4]);
You can also collect into Result
s or Option
s.
use completion::{CompletionStreamExt, completion_stream}; let success_stream = completion_stream! { for i in 0..5 { yield Some(i); } }; let failure_stream = completion_stream! { for i in 0..5 { yield Some(i); } yield None; }; assert_eq!(success_stream.collect::<Option<Vec<_>>>().await, Some(vec![0, 1, 2, 3, 4])); assert_eq!(failure_stream.collect::<Option<Vec<_>>>().await, None);
fn fold<T, F>(self, init: T, f: F) -> Fold<Self, F, T>ⓘNotable traits for Fold<S, F, T>
impl<S, F, T> Future for Fold<S, F, T> where
S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>,
F: FnMut(T, <S as CompletionStream>::Item) -> T, type Output = Self::Output;
where
F: FnMut(T, Self::Item) -> T,
Self: Sized,
[src]
Notable traits for Fold<S, F, T>
impl<S, F, T> Future for Fold<S, F, T> where
S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>,
F: FnMut(T, <S as CompletionStream>::Item) -> T, type Output = Self::Output;
F: FnMut(T, Self::Item) -> T,
Self: Sized,
Accumulate a value over a stream.
Fold
stores an accumulator that is initially set to init
. Whenever the stream produces
a new item, it calls the function f
with the accumulator and new item, which then returns
the new value of the accumulator. Once the stream is finished, it returns the accumulator.
Examples
use completion::{CompletionStreamExt, completion_stream}; let stream = completion_stream! { yield 1; yield 8; yield 2; }; assert_eq!(stream.fold(0, |acc, x| acc + x).await, 11);
fn all<F: FnMut(Self::Item) -> bool>(&mut self, f: F) -> All<'_, Self, F>ⓘNotable traits for All<'_, S, F>
impl<S: Unpin + ?Sized, F> Future for All<'_, S, F> where
S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>,
F: FnMut(<S as CompletionStream>::Item) -> bool, type Output = bool;
where
Self: Unpin,
[src]
Notable traits for All<'_, S, F>
impl<S: Unpin + ?Sized, F> Future for All<'_, S, F> where
S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>,
F: FnMut(<S as CompletionStream>::Item) -> bool, type Output = bool;
Self: Unpin,
Check if all the elements in the stream match a predicate.
This is short-circuiting; it will stop once it finds a false
.
An empty stream returns true
.
Examples
use completion::{CompletionStreamExt, StreamExt}; use futures_lite::stream; assert!(stream::iter(0..10).into_completion().all(|x| x < 10).await); assert!(!stream::iter(0..8).into_completion().all(|x| x < 7).await); assert!(stream::empty::<()>().into_completion().all(|_| false).await);
fn any<F: FnMut(Self::Item) -> bool>(&mut self, f: F) -> Any<'_, Self, F>ⓘNotable traits for Any<'_, S, F>
impl<S: Unpin + ?Sized, F> Future for Any<'_, S, F> where
S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>,
F: FnMut(<S as CompletionStream>::Item) -> bool, type Output = bool;
where
Self: Unpin,
[src]
Notable traits for Any<'_, S, F>
impl<S: Unpin + ?Sized, F> Future for Any<'_, S, F> where
S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>,
F: FnMut(<S as CompletionStream>::Item) -> bool, type Output = bool;
Self: Unpin,
Check if any of the elements in the stream match a predicate.
This is short-circuiting; it will stop once it finds a true
.
An empty stream returns false
.
Examples
use completion::{CompletionStreamExt, StreamExt}; use futures_lite::stream; assert!(stream::iter(0..10).into_completion().any(|x| x == 9).await); assert!(!stream::iter(0..8).into_completion().all(|x| x == 9).await); assert!(!stream::empty::<()>().into_completion().any(|_| true).await);
fn find<P>(&mut self, predicate: P) -> Find<'_, Self, P>ⓘNotable traits for Find<'_, S, P>
impl<S: Unpin + ?Sized, P> Future for Find<'_, S, P> where
S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>,
P: FnMut(&<S as CompletionStream>::Item) -> bool, type Output = Self::Output;
where
Self: Unpin,
P: FnMut(&Self::Item) -> bool,
[src]
Notable traits for Find<'_, S, P>
impl<S: Unpin + ?Sized, P> Future for Find<'_, S, P> where
S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>,
P: FnMut(&<S as CompletionStream>::Item) -> bool, type Output = Self::Output;
Self: Unpin,
P: FnMut(&Self::Item) -> bool,
Search for an element in the stream that satisfies a predicate.
find()
is short-circuiting, it will stop processing as soon as the closure returns
true
.
Examples
use completion::{CompletionStreamExt, StreamExt}; use futures_lite::stream; let mut stream = stream::iter(1..10).into_completion(); // Find the first even number. assert_eq!(stream.find(|x| x % 2 == 0).await, Some(2)); // Find the next odd number. assert_eq!(stream.find(|x| x % 2 == 1).await, Some(3)); // Find short-circuits. assert_eq!(stream.next().await, Some(4));
fn find_map<B, F>(&mut self, f: F) -> FindMap<'_, Self, F>ⓘNotable traits for FindMap<'_, S, F>
impl<S: Unpin + ?Sized, F, B> Future for FindMap<'_, S, F> where
S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>,
F: FnMut(<S as CompletionStream>::Item) -> Option<B>, type Output = Self::Output;
where
Self: Unpin,
F: FnMut(Self::Item) -> Option<B>,
[src]
Notable traits for FindMap<'_, S, F>
impl<S: Unpin + ?Sized, F, B> Future for FindMap<'_, S, F> where
S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>,
F: FnMut(<S as CompletionStream>::Item) -> Option<B>, type Output = Self::Output;
Self: Unpin,
F: FnMut(Self::Item) -> Option<B>,
Finds the first element in a stream for which a function returns Some
.
stream.find_map(f).await
is equivalent to stream.filter_map(f).await.next().await
.
Examples
use completion::{CompletionStreamExt, StreamExt}; use futures_lite::stream; let mut stream = stream::iter(&["lol", "NaN", "2", "5"]).into_completion(); assert_eq!(stream.find_map(|s| s.parse().ok()).await, Some(2)); assert_eq!(stream.find_map(|s| s.parse().ok()).await, Some(5)); assert_eq!(stream.next().await, None);
fn position<P>(&mut self, predicate: P) -> Position<'_, Self, P>ⓘNotable traits for Position<'_, S, P>
impl<S: Unpin + ?Sized, P> Future for Position<'_, S, P> where
S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>,
P: FnMut(<S as CompletionStream>::Item) -> bool, type Output = Self::Output;
where
Self: Unpin,
P: FnMut(Self::Item) -> bool,
[src]
Notable traits for Position<'_, S, P>
impl<S: Unpin + ?Sized, P> Future for Position<'_, S, P> where
S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>,
P: FnMut(<S as CompletionStream>::Item) -> bool, type Output = Self::Output;
Self: Unpin,
P: FnMut(Self::Item) -> bool,
Get the index of an element in the stream.
position()
is short-circuiting, it will stop processing as soon as the closure returns
true
.
Overflow Behaviour
The method does no guarding against overflows, so enumerating more than usize::MAX
elements either produces the wrong result or panics. If debug assertions are enabled, a
panic is guaranteed.
Panics
The returned stream might panic if the to-be-returned index would overflow a usize
.
Examples
use completion::{CompletionStreamExt, StreamExt}; use futures_lite::stream; let mut stream = stream::iter(1..10).into_completion(); assert_eq!(stream.position(|x| x == 4).await, Some(3)); assert_eq!(stream.position(|x| x == 11).await, None);
fn max(self) -> Max<Self>ⓘNotable traits for Max<S>
impl<S> Future for Max<S> where
S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>, type Output = Self::Output;
where
Self: Sized,
Self::Item: Ord,
[src]
Notable traits for Max<S>
impl<S> Future for Max<S> where
S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>, type Output = Self::Output;
Self: Sized,
Self::Item: Ord,
Find the maximum value in the stream.
If several elements are equally maximum, the last element is returned. If the stream is
empty, None
is returned.
Examples
use completion::{CompletionStreamExt, StreamExt}; use futures_lite::stream; assert_eq!(stream::iter(&[1, 5, 2, 7, 4]).into_completion().max().await, Some(&7)); assert_eq!(stream::iter(<Vec<()>>::new()).into_completion().max().await, None); let first = 5; let second = 5; let r = stream::iter(vec![&first, &second]).into_completion().max().await.unwrap(); // `first` and `second` are equal in value, but `second` is chosen because it is later. assert_eq!(r as *const _, &second as *const _);
fn max_by<F>(self, compare: F) -> MaxBy<Self, F>ⓘNotable traits for MaxBy<S, F>
impl<S, F> Future for MaxBy<S, F> where
S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>,
F: FnMut(&<S as CompletionStream>::Item, &<S as CompletionStream>::Item) -> Ordering, type Output = Self::Output;
where
Self: Sized,
F: FnMut(&Self::Item, &Self::Item) -> Ordering,
[src]
Notable traits for MaxBy<S, F>
impl<S, F> Future for MaxBy<S, F> where
S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>,
F: FnMut(&<S as CompletionStream>::Item, &<S as CompletionStream>::Item) -> Ordering, type Output = Self::Output;
Self: Sized,
F: FnMut(&Self::Item, &Self::Item) -> Ordering,
Find the maximum value in the stream using the specified comparison function.
If several elements are equally maximum, the last element is returned. If the stream is
empty, None
is returned.
Examples
use completion::{CompletionStreamExt, StreamExt}; use futures_lite::stream; let a = [("a", 1), ("b", 7), ("c", 2), ("d", 7), ("e", 4)]; let max = stream::iter(&a).into_completion().max_by(|(_, x), (_, y)| x.cmp(y)).await; assert_eq!(max, Some(&("d", 7)));
fn max_by_key<B, F>(self, f: F) -> MaxByKey<Self, B, F>ⓘNotable traits for MaxByKey<S, B, F>
impl<S, B, F> Future for MaxByKey<S, B, F> where
S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>,
F: FnMut(&<S as CompletionStream>::Item) -> B,
B: Ord, type Output = Self::Output;
where
Self: Sized,
B: Ord,
F: FnMut(&Self::Item) -> B,
[src]
Notable traits for MaxByKey<S, B, F>
impl<S, B, F> Future for MaxByKey<S, B, F> where
S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>,
F: FnMut(&<S as CompletionStream>::Item) -> B,
B: Ord, type Output = Self::Output;
Self: Sized,
B: Ord,
F: FnMut(&Self::Item) -> B,
Find the element that gives the maximum value from the specified function.
If several elements are equally maximum, the last element is returned. If the stream is
empty, None
is returned.
Examples
use completion::{CompletionStreamExt, StreamExt}; use futures_lite::stream; let a: &[i32] = &[-3, 2, 10, 5, -10]; let max = stream::iter(a).into_completion().max_by_key(|x| x.abs()).await; assert_eq!(max, Some(&-10));
fn min(self) -> Min<Self>ⓘNotable traits for Min<S>
impl<S> Future for Min<S> where
S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>, type Output = Self::Output;
where
Self: Sized,
Self::Item: Ord,
[src]
Notable traits for Min<S>
impl<S> Future for Min<S> where
S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>, type Output = Self::Output;
Self: Sized,
Self::Item: Ord,
Find the minimum value in the stream.
If several elements are equally minimum, the first element is returned. If the stream is
empty, None
is returned.
Examples
use completion::{CompletionStreamExt, StreamExt}; use futures_lite::stream; assert_eq!(stream::iter(&[5, 7, 1, 3, 2]).into_completion().min().await, Some(&1)); assert_eq!(stream::iter(<Vec<()>>::new()).into_completion().min().await, None); let first = 5; let second = 5; let r = stream::iter(vec![&first, &second]).into_completion().min().await.unwrap(); // `first` and `second` are equal in value, but `first` is chosen because it is earlier. assert_eq!(r as *const _, &first as *const _);
fn min_by<F>(self, compare: F) -> MinBy<Self, F>ⓘNotable traits for MinBy<S, F>
impl<S, F> Future for MinBy<S, F> where
S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>,
F: FnMut(&<S as CompletionStream>::Item, &<S as CompletionStream>::Item) -> Ordering, type Output = Self::Output;
where
Self: Sized,
F: FnMut(&Self::Item, &Self::Item) -> Ordering,
[src]
Notable traits for MinBy<S, F>
impl<S, F> Future for MinBy<S, F> where
S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>,
F: FnMut(&<S as CompletionStream>::Item, &<S as CompletionStream>::Item) -> Ordering, type Output = Self::Output;
Self: Sized,
F: FnMut(&Self::Item, &Self::Item) -> Ordering,
Find the minimum value in the stream using the specified comparison function.
If several elements are equally minimum, the last element is returned. If the stream is
empty, None
is returned.
Examples
use completion::{CompletionStreamExt, StreamExt}; use futures_lite::stream; let a = [("a", 3), ("b", 7), ("c", 1), ("d", 1), ("e", 4)]; let min = stream::iter(&a).into_completion().min_by(|(_, x), (_, y)| x.cmp(y)).await; assert_eq!(min, Some(&("c", 1)));
fn min_by_key<B, F>(self, f: F) -> MinByKey<Self, B, F>ⓘNotable traits for MinByKey<S, B, F>
impl<S, B, F> Future for MinByKey<S, B, F> where
S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>,
F: FnMut(&<S as CompletionStream>::Item) -> B,
B: Ord, type Output = Self::Output;
where
Self: Sized,
B: Ord,
F: FnMut(&Self::Item) -> B,
[src]
Notable traits for MinByKey<S, B, F>
impl<S, B, F> Future for MinByKey<S, B, F> where
S: CompletionStream + Stream<Item = <S as CompletionStream>::Item>,
F: FnMut(&<S as CompletionStream>::Item) -> B,
B: Ord, type Output = Self::Output;
Self: Sized,
B: Ord,
F: FnMut(&Self::Item) -> B,
Find the element that gives the minimum value from the specified function.
If several elements are equally minimum, the last element is returned. If the stream is
empty, None
is returned.
Examples
use completion::{CompletionStreamExt, StreamExt}; use futures_lite::stream; let a: &[i32] = &[-10, 9, 23, -2, 8, 2]; let min = stream::iter(a).into_completion().min_by_key(|x| x.abs()).await; assert_eq!(min, Some(&-2));
fn copied<'a, T: Copy + 'a>(self) -> Copied<Self> where
Self: CompletionStream<Item = &'a T> + Sized,
[src]
Self: CompletionStream<Item = &'a T> + Sized,
Copy all of the elements in the stream.
This is useful when you have a stream over &T
, but you need a stream over T
.
Examples
use completion::{CompletionStreamExt, StreamExt}; use futures_lite::stream; let a = [1, 2, 3]; let v: Vec<i32> = stream::iter(&a).into_completion().copied().collect().await; assert_eq!(v, [1, 2, 3]);
fn cloned<'a, T: Clone + 'a>(self) -> Cloned<Self> where
Self: CompletionStream<Item = &'a T> + Sized,
[src]
Self: CompletionStream<Item = &'a T> + Sized,
Clone all of the elements in the stream.
This is useful when you have a stream over &T
, but you need a stream over T
.
Examples
use completion::{CompletionStreamExt, StreamExt}; use futures_lite::stream; let a = ["1".to_owned(), "2".to_owned(), "3".to_owned()]; let v: Vec<String> = stream::iter(&a).into_completion().cloned().collect().await; assert_eq!(v, ["1".to_owned(), "2".to_owned(), "3".to_owned()]);
fn cycle(self) -> Cycle<Self> where
Self: Sized + Clone,
[src]
Self: Sized + Clone,
Repeat the stream endlessly.
Instead of stopping at None
, this stream will start again, from the beginning. The
returned stream will only return None
when the underlying stream is empty.
Examples
use completion::{CompletionStreamExt, StreamExt}; use futures_lite::stream; let mut stream = stream::iter(0..3).into_completion().cycle(); assert_eq!(stream.next().await, Some(0)); assert_eq!(stream.next().await, Some(1)); assert_eq!(stream.next().await, Some(2)); assert_eq!(stream.next().await, Some(0)); assert_eq!(stream.next().await, Some(1)); assert_eq!(stream.next().await, Some(2)); assert_eq!(stream.next().await, Some(0)); // And so on...
fn boxed<'a>(self) -> BoxCompletionStream<'a, Self::Item> where
Self: Sized + Send + 'a,
[src]
Self: Sized + Send + 'a,
alloc
only.Box the stream, erasing its type.
Examples
use completion::{CompletionStreamExt, StreamExt}; use futures_lite::stream; // These streams are different types, but boxing them makes them the same type. let stream = if some_condition { stream::iter(2..18).into_completion().boxed() } else { stream::iter(vec![5, 3, 7, 8, 2]).into_completion().boxed() };
fn boxed_local<'a>(self) -> LocalBoxCompletionStream<'a, Self::Item> where
Self: Sized + 'a,
[src]
Self: Sized + 'a,
alloc
only.Box the stream locally, erasing its type.
Examples
use completion::{CompletionStreamExt, StreamExt}; use futures_lite::stream; // These streams are different types, but boxing them makes them the same type. let stream = if some_condition { stream::iter(2..18).into_completion().boxed_local() } else { stream::iter(vec![5, 3, 7, 8, 2]).into_completion().boxed_local() };