pub struct Unblock<T> { /* private fields */ }
Expand description
Runs blocking I/O on a thread pool.
Blocking I/O must be isolated from async code. This type moves blocking I/O operations onto a special thread pool while exposing a familiar async interface.
This type implements traits Stream
, AsyncRead
, AsyncWrite
, or AsyncSeek
if the
inner type implements Iterator
, Read
, Write
, or Seek
, respectively.
Caveats
Unblock
is a low-level primitive, and as such it comes with some caveats.
For higher-level primitives built on top of Unblock
, look into async-fs
or
async-process
(on Windows).
Unblock
communicates with I/O operations on the thread pool through a pipe. That means an
async read/write operation simply receives/sends some bytes from/into the pipe. When in reading
mode, the thread pool reads bytes from the I/O handle and forwards them into the pipe until it
becomes full. When in writing mode, the thread pool reads bytes from the pipe and forwards them
into the I/O handle.
Use Unblock::with_capacity()
to configure the capacity of the pipe.
Reading
If you create an Unblock
<
Stdin
>
, read some bytes from it,
and then drop it, a blocked read operation may keep hanging on the thread pool. The next
attempt to read from stdin will lose bytes read by the hanging operation. This is a difficult
problem to solve, so make sure you only use a single stdin handle for the duration of the
entire program.
Writing
If writing data through the AsyncWrite
trait, make sure to flush before dropping the
Unblock
handle or some buffered data might get lost.
Seeking
Because of buffering in the pipe, if Unblock
wraps a File
, a single
read operation may move the file cursor farther than is the span of the operation. In fact,
reading just keeps going in the background until the pipe gets full. Keep this mind when
using AsyncSeek
with relative offsets.
Examples
use blocking::Unblock;
use futures_lite::prelude::*;
let mut stdout = Unblock::new(std::io::stdout());
stdout.write_all(b"Hello world!").await?;
stdout.flush().await?;
Implementations
sourceimpl<T> Unblock<T>
impl<T> Unblock<T>
sourcepub fn with_capacity(cap: usize, io: T) -> Unblock<T>
pub fn with_capacity(cap: usize, io: T) -> Unblock<T>
Wraps a blocking I/O handle into the async Unblock
interface with a custom buffer
capacity.
When communicating with the inner Stream
/Read
/Write
type from async code, data
transferred between blocking and async code goes through a buffer of limited capacity. This
constructor configures that capacity.
The default capacity is:
Examples
use blocking::Unblock;
let stdout = Unblock::with_capacity(64 * 1024, std::io::stdout());
sourcepub async fn get_mut(&'_ mut self) -> &'_ mut T
pub async fn get_mut(&'_ mut self) -> &'_ mut T
Gets a mutable reference to the blocking I/O handle.
This is an async method because the I/O handle might be on the thread pool and needs to be moved onto the current thread before we can get a reference to it.
Examples
use blocking::{unblock, Unblock};
use std::fs::File;
let file = unblock(|| File::create("file.txt")).await?;
let mut file = Unblock::new(file);
let metadata = file.get_mut().await.metadata()?;
sourcepub async fn with_mut<R, F>(&'_ mut self, op: F) -> R where
F: 'static + FnOnce(&mut T) -> R + Send,
R: 'static + Send,
T: 'static + Send,
pub async fn with_mut<R, F>(&'_ mut self, op: F) -> R where
F: 'static + FnOnce(&mut T) -> R + Send,
R: 'static + Send,
T: 'static + Send,
Performs a blocking operation on the I/O handle.
Examples
use blocking::{unblock, Unblock};
use std::fs::File;
let file = unblock(|| File::create("file.txt")).await?;
let mut file = Unblock::new(file);
let metadata = file.with_mut(|f| f.metadata()).await?;
sourcepub async fn into_inner(self) -> T
pub async fn into_inner(self) -> T
Extracts the inner blocking I/O handle.
This is an async method because the I/O handle might be on the thread pool and needs to be moved onto the current thread before we can extract it.
Examples
use blocking::{unblock, Unblock};
use futures_lite::prelude::*;
use std::fs::File;
let file = unblock(|| File::create("file.txt")).await?;
let file = Unblock::new(file);
let file = file.into_inner().await;
Trait Implementations
sourceimpl<T> AsyncRead for Unblock<T> where
T: 'static + Read + Send,
impl<T> AsyncRead for Unblock<T> where
T: 'static + Read + Send,
sourceimpl<T> AsyncWrite for Unblock<T> where
T: 'static + Write + Send,
impl<T> AsyncWrite for Unblock<T> where
T: 'static + Write + Send,
sourcefn poll_write(
self: Pin<&mut Unblock<T>>,
cx: &mut Context<'_>,
buf: &[u8]
) -> Poll<Result<usize, Error>>
fn poll_write(
self: Pin<&mut Unblock<T>>,
cx: &mut Context<'_>,
buf: &[u8]
) -> Poll<Result<usize, Error>>
Attempt to write bytes from buf
into the object. Read more
sourcefn poll_flush(
self: Pin<&mut Unblock<T>>,
cx: &mut Context<'_>
) -> Poll<Result<(), Error>>
fn poll_flush(
self: Pin<&mut Unblock<T>>,
cx: &mut Context<'_>
) -> Poll<Result<(), Error>>
Attempt to flush the object, ensuring that any buffered data reach their destination. Read more
sourceimpl<T> Stream for Unblock<T> where
T: 'static + Iterator + Send,
<T as Iterator>::Item: 'static,
<T as Iterator>::Item: Send,
impl<T> Stream for Unblock<T> where
T: 'static + Iterator + Send,
<T as Iterator>::Item: 'static,
<T as Iterator>::Item: Send,
Auto Trait Implementations
impl<T> !RefUnwindSafe for Unblock<T>
impl<T> Send for Unblock<T> where
T: Send,
impl<T> Sync for Unblock<T> where
T: Sync,
impl<T> Unpin for Unblock<T>
impl<T> !UnwindSafe for Unblock<T>
Blanket Implementations
sourceimpl<R> AsyncReadExt for R where
R: AsyncRead + ?Sized,
impl<R> AsyncReadExt for R where
R: AsyncRead + ?Sized,
sourcefn read(&'a mut self, buf: &'a mut [u8]) -> ReadFuture<'a, Self>ⓘNotable traits for ReadFuture<'_, R>impl<'_, R> Future for ReadFuture<'_, R> where
R: AsyncRead + Unpin + ?Sized, type Output = Result<usize, Error>;
where
Self: Unpin,
fn read(&'a mut self, buf: &'a mut [u8]) -> ReadFuture<'a, Self>ⓘNotable traits for ReadFuture<'_, R>impl<'_, R> Future for ReadFuture<'_, R> where
R: AsyncRead + Unpin + ?Sized, type Output = Result<usize, Error>;
where
Self: Unpin,
R: AsyncRead + Unpin + ?Sized, type Output = Result<usize, Error>;
Reads some bytes from the byte stream. Read more
sourcefn read_vectored(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectoredFuture<'a, Self>ⓘNotable traits for ReadVectoredFuture<'_, R>impl<'_, R> Future for ReadVectoredFuture<'_, R> where
R: AsyncRead + Unpin + ?Sized, type Output = Result<usize, Error>;
where
Self: Unpin,
fn read_vectored(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectoredFuture<'a, Self>ⓘNotable traits for ReadVectoredFuture<'_, R>impl<'_, R> Future for ReadVectoredFuture<'_, R> where
R: AsyncRead + Unpin + ?Sized, type Output = Result<usize, Error>;
where
Self: Unpin,
R: AsyncRead + Unpin + ?Sized, type Output = Result<usize, Error>;
sourcefn read_to_end(
&'a mut self,
buf: &'a mut Vec<u8, Global>
) -> ReadToEndFuture<'a, Self>ⓘNotable traits for ReadToEndFuture<'_, R>impl<'_, R> Future for ReadToEndFuture<'_, R> where
R: AsyncRead + Unpin + ?Sized, type Output = Result<usize, Error>;
where
Self: Unpin,
fn read_to_end(
&'a mut self,
buf: &'a mut Vec<u8, Global>
) -> ReadToEndFuture<'a, Self>ⓘNotable traits for ReadToEndFuture<'_, R>impl<'_, R> Future for ReadToEndFuture<'_, R> where
R: AsyncRead + Unpin + ?Sized, type Output = Result<usize, Error>;
where
Self: Unpin,
R: AsyncRead + Unpin + ?Sized, type Output = Result<usize, Error>;
sourcefn read_to_string(
&'a mut self,
buf: &'a mut String
) -> ReadToStringFuture<'a, Self>ⓘNotable traits for ReadToStringFuture<'_, R>impl<'_, R> Future for ReadToStringFuture<'_, R> where
R: AsyncRead + Unpin + ?Sized, type Output = Result<usize, Error>;
where
Self: Unpin,
fn read_to_string(
&'a mut self,
buf: &'a mut String
) -> ReadToStringFuture<'a, Self>ⓘNotable traits for ReadToStringFuture<'_, R>impl<'_, R> Future for ReadToStringFuture<'_, R> where
R: AsyncRead + Unpin + ?Sized, type Output = Result<usize, Error>;
where
Self: Unpin,
R: AsyncRead + Unpin + ?Sized, type Output = Result<usize, Error>;
sourcefn read_exact(&'a mut self, buf: &'a mut [u8]) -> ReadExactFuture<'a, Self>ⓘNotable traits for ReadExactFuture<'_, R>impl<'_, R> Future for ReadExactFuture<'_, R> where
R: AsyncRead + Unpin + ?Sized, type Output = Result<(), Error>;
where
Self: Unpin,
fn read_exact(&'a mut self, buf: &'a mut [u8]) -> ReadExactFuture<'a, Self>ⓘNotable traits for ReadExactFuture<'_, R>impl<'_, R> Future for ReadExactFuture<'_, R> where
R: AsyncRead + Unpin + ?Sized, type Output = Result<(), Error>;
where
Self: Unpin,
R: AsyncRead + Unpin + ?Sized, type Output = Result<(), Error>;
Reads the exact number of bytes required to fill buf
. Read more
sourcefn take(self, limit: u64) -> Take<Self>
fn take(self, limit: u64) -> Take<Self>
Creates an adapter which will read at most limit
bytes from it. Read more
sourcefn chain<R>(self, next: R) -> Chain<Self, R> where
R: AsyncRead,
fn chain<R>(self, next: R) -> Chain<Self, R> where
R: AsyncRead,
Creates an adapter which will chain this stream with another. Read more
sourcefn boxed_reader<'a>(self) -> Pin<Box<dyn AsyncRead + Send + 'a, Global>>ⓘNotable traits for Pin<P>impl<P> Future for Pin<P> where
P: DerefMut,
<P as Deref>::Target: Future, type Output = <<P as Deref>::Target as Future>::Output;
where
Self: 'a + Send,
fn boxed_reader<'a>(self) -> Pin<Box<dyn AsyncRead + Send + 'a, Global>>ⓘNotable traits for Pin<P>impl<P> Future for Pin<P> where
P: DerefMut,
<P as Deref>::Target: Future, type Output = <<P as Deref>::Target as Future>::Output;
where
Self: 'a + Send,
P: DerefMut,
<P as Deref>::Target: Future, type Output = <<P as Deref>::Target as Future>::Output;
Boxes the reader and changes its type to dyn AsyncRead + Send + 'a
. Read more
sourceimpl<S> AsyncSeekExt for S where
S: AsyncSeek + ?Sized,
impl<S> AsyncSeekExt for S where
S: AsyncSeek + ?Sized,
sourceimpl<W> AsyncWriteExt for W where
W: AsyncWrite + ?Sized,
impl<W> AsyncWriteExt for W where
W: AsyncWrite + ?Sized,
sourcefn write(&'a mut self, buf: &'a [u8]) -> WriteFuture<'a, Self>ⓘNotable traits for WriteFuture<'_, W>impl<'_, W> Future for WriteFuture<'_, W> where
W: AsyncWrite + Unpin + ?Sized, type Output = Result<usize, Error>;
where
Self: Unpin,
fn write(&'a mut self, buf: &'a [u8]) -> WriteFuture<'a, Self>ⓘNotable traits for WriteFuture<'_, W>impl<'_, W> Future for WriteFuture<'_, W> where
W: AsyncWrite + Unpin + ?Sized, type Output = Result<usize, Error>;
where
Self: Unpin,
W: AsyncWrite + Unpin + ?Sized, type Output = Result<usize, Error>;
Writes some bytes into the byte stream. Read more
sourcefn write_vectored(
&'a mut self,
bufs: &'a [IoSlice<'a>]
) -> WriteVectoredFuture<'a, Self>ⓘNotable traits for WriteVectoredFuture<'_, W>impl<'_, W> Future for WriteVectoredFuture<'_, W> where
W: AsyncWrite + Unpin + ?Sized, type Output = Result<usize, Error>;
where
Self: Unpin,
fn write_vectored(
&'a mut self,
bufs: &'a [IoSlice<'a>]
) -> WriteVectoredFuture<'a, Self>ⓘNotable traits for WriteVectoredFuture<'_, W>impl<'_, W> Future for WriteVectoredFuture<'_, W> where
W: AsyncWrite + Unpin + ?Sized, type Output = Result<usize, Error>;
where
Self: Unpin,
W: AsyncWrite + Unpin + ?Sized, type Output = Result<usize, Error>;
sourcefn write_all(&'a mut self, buf: &'a [u8]) -> WriteAllFuture<'a, Self>ⓘNotable traits for WriteAllFuture<'_, W>impl<'_, W> Future for WriteAllFuture<'_, W> where
W: AsyncWrite + Unpin + ?Sized, type Output = Result<(), Error>;
where
Self: Unpin,
fn write_all(&'a mut self, buf: &'a [u8]) -> WriteAllFuture<'a, Self>ⓘNotable traits for WriteAllFuture<'_, W>impl<'_, W> Future for WriteAllFuture<'_, W> where
W: AsyncWrite + Unpin + ?Sized, type Output = Result<(), Error>;
where
Self: Unpin,
W: AsyncWrite + Unpin + ?Sized, type Output = Result<(), Error>;
Writes an entire buffer into the byte stream. Read more
sourcefn flush(&mut self) -> FlushFuture<'_, Self>ⓘNotable traits for FlushFuture<'_, W>impl<'_, W> Future for FlushFuture<'_, W> where
W: AsyncWrite + Unpin + ?Sized, type Output = Result<(), Error>;
where
Self: Unpin,
fn flush(&mut self) -> FlushFuture<'_, Self>ⓘNotable traits for FlushFuture<'_, W>impl<'_, W> Future for FlushFuture<'_, W> where
W: AsyncWrite + Unpin + ?Sized, type Output = Result<(), Error>;
where
Self: Unpin,
W: AsyncWrite + Unpin + ?Sized, type Output = Result<(), Error>;
Flushes the stream to ensure that all buffered contents reach their destination. Read more
sourcefn close(&mut self) -> CloseFuture<'_, Self>ⓘNotable traits for CloseFuture<'_, W>impl<'_, W> Future for CloseFuture<'_, W> where
W: AsyncWrite + Unpin + ?Sized, type Output = Result<(), Error>;
where
Self: Unpin,
fn close(&mut self) -> CloseFuture<'_, Self>ⓘNotable traits for CloseFuture<'_, W>impl<'_, W> Future for CloseFuture<'_, W> where
W: AsyncWrite + Unpin + ?Sized, type Output = Result<(), Error>;
where
Self: Unpin,
W: AsyncWrite + Unpin + ?Sized, type Output = Result<(), Error>;
Closes the writer. Read more
sourcefn boxed_writer<'a>(self) -> Pin<Box<dyn AsyncWrite + Send + 'a, Global>>ⓘNotable traits for Pin<P>impl<P> Future for Pin<P> where
P: DerefMut,
<P as Deref>::Target: Future, type Output = <<P as Deref>::Target as Future>::Output;
where
Self: 'a + Send,
fn boxed_writer<'a>(self) -> Pin<Box<dyn AsyncWrite + Send + 'a, Global>>ⓘNotable traits for Pin<P>impl<P> Future for Pin<P> where
P: DerefMut,
<P as Deref>::Target: Future, type Output = <<P as Deref>::Target as Future>::Output;
where
Self: 'a + Send,
P: DerefMut,
<P as Deref>::Target: Future, type Output = <<P as Deref>::Target as Future>::Output;
Boxes the writer and changes its type to dyn AsyncWrite + Send + 'a
. Read more
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<S> StreamExt for S where
S: Stream + ?Sized,
impl<S> StreamExt for S where
S: Stream + ?Sized,
sourcefn poll_next(&mut self, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> where
Self: Unpin,
fn poll_next(&mut self, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> where
Self: Unpin,
A convenience for calling Stream::poll_next()
on !
Unpin
types.
sourcefn next(&mut self) -> NextFuture<'_, Self>ⓘNotable traits for NextFuture<'_, S>impl<'_, S> Future for NextFuture<'_, S> where
S: Stream + Unpin + ?Sized, type Output = Option<<S as Stream>::Item>;
where
Self: Unpin,
fn next(&mut self) -> NextFuture<'_, Self>ⓘNotable traits for NextFuture<'_, S>impl<'_, S> Future for NextFuture<'_, S> where
S: Stream + Unpin + ?Sized, type Output = Option<<S as Stream>::Item>;
where
Self: Unpin,
S: Stream + Unpin + ?Sized, type Output = Option<<S as Stream>::Item>;
Retrieves the next item in the stream. Read more
sourcefn try_next<T, E>(&mut self) -> TryNextFuture<'_, Self>ⓘNotable traits for TryNextFuture<'_, S>impl<'_, T, E, S> Future for TryNextFuture<'_, S> where
S: Stream<Item = Result<T, E>> + Unpin + ?Sized, type Output = Result<Option<T>, E>;
where
Self: Stream<Item = Result<T, E>> + Unpin,
fn try_next<T, E>(&mut self) -> TryNextFuture<'_, Self>ⓘNotable traits for TryNextFuture<'_, S>impl<'_, T, E, S> Future for TryNextFuture<'_, S> where
S: Stream<Item = Result<T, E>> + Unpin + ?Sized, type Output = Result<Option<T>, E>;
where
Self: Stream<Item = Result<T, E>> + Unpin,
S: Stream<Item = Result<T, E>> + Unpin + ?Sized, type Output = Result<Option<T>, E>;
Retrieves the next item in the stream. Read more
sourcefn count(self) -> CountFuture<Self>ⓘNotable traits for CountFuture<S>impl<S> Future for CountFuture<S> where
S: Stream + ?Sized, type Output = usize;
fn count(self) -> CountFuture<Self>ⓘNotable traits for CountFuture<S>impl<S> Future for CountFuture<S> where
S: Stream + ?Sized, type Output = usize;
S: Stream + ?Sized, type Output = usize;
Counts the number of items in the stream. Read more
sourcefn map<T, F>(self, f: F) -> Map<Self, F> where
F: FnMut(Self::Item) -> T,
fn map<T, F>(self, f: F) -> Map<Self, F> where
F: FnMut(Self::Item) -> T,
Maps items of the stream to new values using a closure. Read more
sourcefn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F> where
U: Stream,
F: FnMut(Self::Item) -> U,
fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F> where
U: Stream,
F: FnMut(Self::Item) -> U,
Maps items to streams and then concatenates them. Read more
sourcefn flatten(self) -> Flatten<Self> where
Self::Item: Stream,
fn flatten(self) -> Flatten<Self> where
Self::Item: Stream,
Concatenates inner streams. Read more
sourcefn then<F, Fut>(self, f: F) -> Then<Self, F, Fut> where
F: FnMut(Self::Item) -> Fut,
Fut: Future,
fn then<F, Fut>(self, f: F) -> Then<Self, F, Fut> where
F: FnMut(Self::Item) -> Fut,
Fut: Future,
Maps items of the stream to new values using an async closure. Read more
sourcefn filter<P>(self, predicate: P) -> Filter<Self, P> where
P: FnMut(&Self::Item) -> bool,
fn filter<P>(self, predicate: P) -> Filter<Self, P> where
P: FnMut(&Self::Item) -> bool,
Keeps items of the stream for which predicate
returns true
. Read more
sourcefn filter_map<T, F>(self, f: F) -> FilterMap<Self, F> where
F: FnMut(Self::Item) -> Option<T>,
fn filter_map<T, F>(self, f: F) -> FilterMap<Self, F> where
F: FnMut(Self::Item) -> Option<T>,
Filters and maps items of the stream using a closure. Read more
sourcefn take_while<P>(self, predicate: P) -> TakeWhile<Self, P> where
P: FnMut(&Self::Item) -> bool,
fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P> where
P: FnMut(&Self::Item) -> bool,
Takes items while predicate
returns true
. Read more
sourcefn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P> where
P: FnMut(&Self::Item) -> bool,
fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P> where
P: FnMut(&Self::Item) -> bool,
Skips items while predicate
returns true
. Read more
sourcefn chain<U>(self, other: U) -> Chain<Self, U> where
U: Stream<Item = Self::Item>,
fn chain<U>(self, other: U) -> Chain<Self, U> where
U: Stream<Item = Self::Item>,
Appends another stream to the end of this one. Read more
sourcefn cloned<'a, T>(self) -> Cloned<Self> where
Self: Stream<Item = &'a T>,
T: 'a + Clone,
fn cloned<'a, T>(self) -> Cloned<Self> where
Self: Stream<Item = &'a T>,
T: 'a + Clone,
Clones all items. Read more
sourcefn copied<'a, T>(self) -> Copied<Self> where
Self: Stream<Item = &'a T>,
T: 'a + Copy,
fn copied<'a, T>(self) -> Copied<Self> where
Self: Stream<Item = &'a T>,
T: 'a + Copy,
Copies all items. Read more
sourcefn collect<C>(self) -> CollectFuture<Self, C>ⓘNotable traits for CollectFuture<S, C>impl<S, C> Future for CollectFuture<S, C> where
S: Stream,
C: Default + Extend<<S as Stream>::Item>, type Output = C;
where
C: Default + Extend<Self::Item>,
fn collect<C>(self) -> CollectFuture<Self, C>ⓘNotable traits for CollectFuture<S, C>impl<S, C> Future for CollectFuture<S, C> where
S: Stream,
C: Default + Extend<<S as Stream>::Item>, type Output = C;
where
C: Default + Extend<Self::Item>,
S: Stream,
C: Default + Extend<<S as Stream>::Item>, type Output = C;
Collects all items in the stream into a collection. Read more
sourcefn try_collect<T, E, C>(self) -> TryCollectFuture<Self, C>ⓘNotable traits for TryCollectFuture<S, C>impl<T, E, S, C> Future for TryCollectFuture<S, C> where
S: Stream<Item = Result<T, E>>,
C: Default + Extend<T>, type Output = Result<C, E>;
where
Self: Stream<Item = Result<T, E>>,
C: Default + Extend<T>,
fn try_collect<T, E, C>(self) -> TryCollectFuture<Self, C>ⓘNotable traits for TryCollectFuture<S, C>impl<T, E, S, C> Future for TryCollectFuture<S, C> where
S: Stream<Item = Result<T, E>>,
C: Default + Extend<T>, type Output = Result<C, E>;
where
Self: Stream<Item = Result<T, E>>,
C: Default + Extend<T>,
S: Stream<Item = Result<T, E>>,
C: Default + Extend<T>, type Output = Result<C, E>;
Collects all items in the fallible stream into a collection. Read more
sourcefn partition<B, P>(self, predicate: P) -> PartitionFuture<Self, P, B>ⓘNotable traits for PartitionFuture<S, P, B>impl<S, P, B> Future for PartitionFuture<S, P, B> where
S: Stream,
P: FnMut(&<S as Stream>::Item) -> bool,
B: Default + Extend<<S as Stream>::Item>, type Output = (B, B);
where
B: Default + Extend<Self::Item>,
P: FnMut(&Self::Item) -> bool,
fn partition<B, P>(self, predicate: P) -> PartitionFuture<Self, P, B>ⓘNotable traits for PartitionFuture<S, P, B>impl<S, P, B> Future for PartitionFuture<S, P, B> where
S: Stream,
P: FnMut(&<S as Stream>::Item) -> bool,
B: Default + Extend<<S as Stream>::Item>, type Output = (B, B);
where
B: Default + Extend<Self::Item>,
P: FnMut(&Self::Item) -> bool,
S: Stream,
P: FnMut(&<S as Stream>::Item) -> bool,
B: Default + Extend<<S as Stream>::Item>, type Output = (B, B);
Partitions items into those for which predicate
is true
and those for which it is
false
, and then collects them into two collections. Read more
sourcefn fold<T, F>(self, init: T, f: F) -> FoldFuture<Self, F, T>ⓘNotable traits for FoldFuture<S, F, T>impl<S, F, T> Future for FoldFuture<S, F, T> where
S: Stream,
F: FnMut(T, <S as Stream>::Item) -> T, type Output = T;
where
F: FnMut(T, Self::Item) -> T,
fn fold<T, F>(self, init: T, f: F) -> FoldFuture<Self, F, T>ⓘNotable traits for FoldFuture<S, F, T>impl<S, F, T> Future for FoldFuture<S, F, T> where
S: Stream,
F: FnMut(T, <S as Stream>::Item) -> T, type Output = T;
where
F: FnMut(T, Self::Item) -> T,
S: Stream,
F: FnMut(T, <S as Stream>::Item) -> T, type Output = T;
Accumulates a computation over the stream. Read more
sourcefn try_fold<T, E, F, B>(
&mut self,
init: B,
f: F
) -> TryFoldFuture<'_, Self, F, B>ⓘNotable traits for TryFoldFuture<'a, S, F, B>impl<'a, T, E, S, F, B> Future for TryFoldFuture<'a, S, F, B> where
S: Stream<Item = Result<T, E>> + Unpin,
F: FnMut(B, T) -> Result<B, E>, type Output = Result<B, E>;
where
Self: Stream<Item = Result<T, E>> + Unpin,
F: FnMut(B, T) -> Result<B, E>,
fn try_fold<T, E, F, B>(
&mut self,
init: B,
f: F
) -> TryFoldFuture<'_, Self, F, B>ⓘNotable traits for TryFoldFuture<'a, S, F, B>impl<'a, T, E, S, F, B> Future for TryFoldFuture<'a, S, F, B> where
S: Stream<Item = Result<T, E>> + Unpin,
F: FnMut(B, T) -> Result<B, E>, type Output = Result<B, E>;
where
Self: Stream<Item = Result<T, E>> + Unpin,
F: FnMut(B, T) -> Result<B, E>,
S: Stream<Item = Result<T, E>> + Unpin,
F: FnMut(B, T) -> Result<B, E>, type Output = Result<B, E>;
Accumulates a fallible computation over the stream. Read more
sourcefn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F> where
F: FnMut(&mut St, Self::Item) -> Option<B>,
fn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F> where
F: FnMut(&mut St, Self::Item) -> Option<B>,
Maps items of the stream to new values using a state value and a closure. Read more
sourcefn cycle(self) -> Cycle<Self> where
Self: Clone,
fn cycle(self) -> Cycle<Self> where
Self: Clone,
Repeats the stream from beginning to end, forever. Read more
sourcefn enumerate(self) -> Enumerate<Self>
fn enumerate(self) -> Enumerate<Self>
Enumerates items, mapping them to (index, item)
. Read more
sourcefn inspect<F>(self, f: F) -> Inspect<Self, F> where
F: FnMut(&Self::Item),
fn inspect<F>(self, f: F) -> Inspect<Self, F> where
F: FnMut(&Self::Item),
Calls a closure on each item and passes it on. Read more
sourcefn nth(&mut self, n: usize) -> NthFuture<'_, Self>ⓘNotable traits for NthFuture<'a, S>impl<'a, S> Future for NthFuture<'a, S> where
S: Stream + Unpin + ?Sized, type Output = Option<<S as Stream>::Item>;
where
Self: Unpin,
fn nth(&mut self, n: usize) -> NthFuture<'_, Self>ⓘNotable traits for NthFuture<'a, S>impl<'a, S> Future for NthFuture<'a, S> where
S: Stream + Unpin + ?Sized, type Output = Option<<S as Stream>::Item>;
where
Self: Unpin,
S: Stream + Unpin + ?Sized, type Output = Option<<S as Stream>::Item>;
Gets the n
th item of the stream. Read more
sourcefn last(self) -> LastFuture<Self>ⓘNotable traits for LastFuture<S>impl<S> Future for LastFuture<S> where
S: Stream, type Output = Option<<S as Stream>::Item>;
fn last(self) -> LastFuture<Self>ⓘNotable traits for LastFuture<S>impl<S> Future for LastFuture<S> where
S: Stream, type Output = Option<<S as Stream>::Item>;
S: Stream, type Output = Option<<S as Stream>::Item>;
Returns the last item in the stream. Read more
sourcefn find<P>(&mut self, predicate: P) -> FindFuture<'_, Self, P>ⓘNotable traits for FindFuture<'a, S, P>impl<'a, S, P> Future for FindFuture<'a, S, P> where
S: Stream + Unpin + ?Sized,
P: FnMut(&<S as Stream>::Item) -> bool, type Output = Option<<S as Stream>::Item>;
where
Self: Unpin,
P: FnMut(&Self::Item) -> bool,
fn find<P>(&mut self, predicate: P) -> FindFuture<'_, Self, P>ⓘNotable traits for FindFuture<'a, S, P>impl<'a, S, P> Future for FindFuture<'a, S, P> where
S: Stream + Unpin + ?Sized,
P: FnMut(&<S as Stream>::Item) -> bool, type Output = Option<<S as Stream>::Item>;
where
Self: Unpin,
P: FnMut(&Self::Item) -> bool,
S: Stream + Unpin + ?Sized,
P: FnMut(&<S as Stream>::Item) -> bool, type Output = Option<<S as Stream>::Item>;
Finds the first item of the stream for which predicate
returns true
. Read more
sourcefn find_map<F, B>(&mut self, f: F) -> FindMapFuture<'_, Self, F>ⓘNotable traits for FindMapFuture<'a, S, F>impl<'a, S, B, F> Future for FindMapFuture<'a, S, F> where
S: Stream + Unpin + ?Sized,
F: FnMut(<S as Stream>::Item) -> Option<B>, type Output = Option<B>;
where
Self: Unpin,
F: FnMut(Self::Item) -> Option<B>,
fn find_map<F, B>(&mut self, f: F) -> FindMapFuture<'_, Self, F>ⓘNotable traits for FindMapFuture<'a, S, F>impl<'a, S, B, F> Future for FindMapFuture<'a, S, F> where
S: Stream + Unpin + ?Sized,
F: FnMut(<S as Stream>::Item) -> Option<B>, type Output = Option<B>;
where
Self: Unpin,
F: FnMut(Self::Item) -> Option<B>,
S: Stream + Unpin + ?Sized,
F: FnMut(<S as Stream>::Item) -> Option<B>, type Output = Option<B>;
sourcefn position<P>(&mut self, predicate: P) -> PositionFuture<'_, Self, P>ⓘNotable traits for PositionFuture<'a, S, P>impl<'a, S, P> Future for PositionFuture<'a, S, P> where
S: Stream + Unpin + ?Sized,
P: FnMut(<S as Stream>::Item) -> bool, type Output = Option<usize>;
where
Self: Unpin,
P: FnMut(Self::Item) -> bool,
fn position<P>(&mut self, predicate: P) -> PositionFuture<'_, Self, P>ⓘNotable traits for PositionFuture<'a, S, P>impl<'a, S, P> Future for PositionFuture<'a, S, P> where
S: Stream + Unpin + ?Sized,
P: FnMut(<S as Stream>::Item) -> bool, type Output = Option<usize>;
where
Self: Unpin,
P: FnMut(Self::Item) -> bool,
S: Stream + Unpin + ?Sized,
P: FnMut(<S as Stream>::Item) -> bool, type Output = Option<usize>;
Finds the index of the first item of the stream for which predicate
returns true
. Read more
sourcefn all<P>(&mut self, predicate: P) -> AllFuture<'_, Self, P>ⓘNotable traits for AllFuture<'_, S, P>impl<'_, S, P> Future for AllFuture<'_, S, P> where
S: Stream + Unpin + ?Sized,
P: FnMut(<S as Stream>::Item) -> bool, type Output = bool;
where
Self: Unpin,
P: FnMut(Self::Item) -> bool,
fn all<P>(&mut self, predicate: P) -> AllFuture<'_, Self, P>ⓘNotable traits for AllFuture<'_, S, P>impl<'_, S, P> Future for AllFuture<'_, S, P> where
S: Stream + Unpin + ?Sized,
P: FnMut(<S as Stream>::Item) -> bool, type Output = bool;
where
Self: Unpin,
P: FnMut(Self::Item) -> bool,
S: Stream + Unpin + ?Sized,
P: FnMut(<S as Stream>::Item) -> bool, type Output = bool;
Tests if predicate
returns true
for all items in the stream. Read more
sourcefn any<P>(&mut self, predicate: P) -> AnyFuture<'_, Self, P>ⓘNotable traits for AnyFuture<'_, S, P>impl<'_, S, P> Future for AnyFuture<'_, S, P> where
S: Stream + Unpin + ?Sized,
P: FnMut(<S as Stream>::Item) -> bool, type Output = bool;
where
Self: Unpin,
P: FnMut(Self::Item) -> bool,
fn any<P>(&mut self, predicate: P) -> AnyFuture<'_, Self, P>ⓘNotable traits for AnyFuture<'_, S, P>impl<'_, S, P> Future for AnyFuture<'_, S, P> where
S: Stream + Unpin + ?Sized,
P: FnMut(<S as Stream>::Item) -> bool, type Output = bool;
where
Self: Unpin,
P: FnMut(Self::Item) -> bool,
S: Stream + Unpin + ?Sized,
P: FnMut(<S as Stream>::Item) -> bool, type Output = bool;
Tests if predicate
returns true
for any item in the stream. Read more
sourcefn for_each<F>(self, f: F) -> ForEachFuture<Self, F>ⓘNotable traits for ForEachFuture<S, F>impl<S, F> Future for ForEachFuture<S, F> where
S: Stream,
F: FnMut(<S as Stream>::Item), type Output = ();
where
F: FnMut(Self::Item),
fn for_each<F>(self, f: F) -> ForEachFuture<Self, F>ⓘNotable traits for ForEachFuture<S, F>impl<S, F> Future for ForEachFuture<S, F> where
S: Stream,
F: FnMut(<S as Stream>::Item), type Output = ();
where
F: FnMut(Self::Item),
S: Stream,
F: FnMut(<S as Stream>::Item), type Output = ();
Calls a closure on each item of the stream. Read more
sourcefn try_for_each<F, E>(&mut self, f: F) -> TryForEachFuture<'_, Self, F>ⓘNotable traits for TryForEachFuture<'a, S, F>impl<'a, S, F, E> Future for TryForEachFuture<'a, S, F> where
S: Stream + Unpin + ?Sized,
F: FnMut(<S as Stream>::Item) -> Result<(), E>, type Output = Result<(), E>;
where
Self: Unpin,
F: FnMut(Self::Item) -> Result<(), E>,
fn try_for_each<F, E>(&mut self, f: F) -> TryForEachFuture<'_, Self, F>ⓘNotable traits for TryForEachFuture<'a, S, F>impl<'a, S, F, E> Future for TryForEachFuture<'a, S, F> where
S: Stream + Unpin + ?Sized,
F: FnMut(<S as Stream>::Item) -> Result<(), E>, type Output = Result<(), E>;
where
Self: Unpin,
F: FnMut(Self::Item) -> Result<(), E>,
S: Stream + Unpin + ?Sized,
F: FnMut(<S as Stream>::Item) -> Result<(), E>, type Output = Result<(), E>;
Calls a fallible closure on each item of the stream, stopping on first error. Read more
sourcefn zip<U>(self, other: U) -> Zip<Self, U> where
U: Stream,
fn zip<U>(self, other: U) -> Zip<Self, U> where
U: Stream,
Zips up two streams into a single stream of pairs. Read more
sourcefn unzip<A, B, FromA, FromB>(self) -> UnzipFuture<Self, FromA, FromB>ⓘNotable traits for UnzipFuture<S, FromA, FromB>impl<S, A, B, FromA, FromB> Future for UnzipFuture<S, FromA, FromB> where
S: Stream<Item = (A, B)>,
FromA: Default + Extend<A>,
FromB: Default + Extend<B>, type Output = (FromA, FromB);
where
FromA: Default + Extend<A>,
FromB: Default + Extend<B>,
Self: Stream<Item = (A, B)>,
fn unzip<A, B, FromA, FromB>(self) -> UnzipFuture<Self, FromA, FromB>ⓘNotable traits for UnzipFuture<S, FromA, FromB>impl<S, A, B, FromA, FromB> Future for UnzipFuture<S, FromA, FromB> where
S: Stream<Item = (A, B)>,
FromA: Default + Extend<A>,
FromB: Default + Extend<B>, type Output = (FromA, FromB);
where
FromA: Default + Extend<A>,
FromB: Default + Extend<B>,
Self: Stream<Item = (A, B)>,
S: Stream<Item = (A, B)>,
FromA: Default + Extend<A>,
FromB: Default + Extend<B>, type Output = (FromA, FromB);
Collects a stream of pairs into a pair of collections. Read more
sourcefn or<S>(self, other: S) -> Or<Self, S> where
S: Stream<Item = Self::Item>,
fn or<S>(self, other: S) -> Or<Self, S> where
S: Stream<Item = Self::Item>,
Merges with other
stream, preferring items from self
whenever both streams are ready. Read more
sourcefn race<S>(self, other: S) -> Race<Self, S> where
S: Stream<Item = Self::Item>,
fn race<S>(self, other: S) -> Race<Self, S> where
S: Stream<Item = Self::Item>,
Merges with other
stream, with no preference for either stream when both are ready. Read more
sourcefn boxed<'a>(
self
) -> Pin<Box<dyn Stream<Item = Self::Item> + Send + 'a, Global>>ⓘNotable traits for Pin<P>impl<P> Future for Pin<P> where
P: DerefMut,
<P as Deref>::Target: Future, type Output = <<P as Deref>::Target as Future>::Output;
where
Self: 'a + Send,
fn boxed<'a>(
self
) -> Pin<Box<dyn Stream<Item = Self::Item> + Send + 'a, Global>>ⓘNotable traits for Pin<P>impl<P> Future for Pin<P> where
P: DerefMut,
<P as Deref>::Target: Future, type Output = <<P as Deref>::Target as Future>::Output;
where
Self: 'a + Send,
P: DerefMut,
<P as Deref>::Target: Future, type Output = <<P as Deref>::Target as Future>::Output;
Boxes the stream and changes its type to dyn Stream + Send + 'a
. Read more
sourcefn boxed_local<'a>(self) -> Pin<Box<dyn Stream<Item = Self::Item> + 'a, Global>>ⓘNotable traits for Pin<P>impl<P> Future for Pin<P> where
P: DerefMut,
<P as Deref>::Target: Future, type Output = <<P as Deref>::Target as Future>::Output;
where
Self: 'a,
fn boxed_local<'a>(self) -> Pin<Box<dyn Stream<Item = Self::Item> + 'a, Global>>ⓘNotable traits for Pin<P>impl<P> Future for Pin<P> where
P: DerefMut,
<P as Deref>::Target: Future, type Output = <<P as Deref>::Target as Future>::Output;
where
Self: 'a,
P: DerefMut,
<P as Deref>::Target: Future, type Output = <<P as Deref>::Target as Future>::Output;
Boxes the stream and changes its type to dyn Stream + 'a
. Read more