pub struct StdWriteAdapterFuture<W, T, F> { /* private fields */ }io only.Expand description
An asynchronous operation implemented using a restricted function taking std::io::Write.
This is a Future that calls F each time it’s polled, passing in a restricted writer.
The closure F may pass this writer to other functions which require std::io::Write as
long as those functions guarantee correct restarting in the presence of WouldBlock
errors.
E.g. given fn perform_single_write(&mut self, writer: impl Write) -> io::Result<()> which
guarantees to keep consistent state in self even if writer returns error, one might
write code like this:
StdWriteAdapterFuture::new_assuming_correct_usage(writer, |writer| {
if self.needs_write() {
match self.perform_single_write() {
Ok(()) => (),
Err(error) if error.kind() == ErrorKind::WouldBlock => {
Poll::Pending
}
Err(error) => Poll::Ready(Err(error)),
}
} else {
Poll::Ready(Ok(()))
}
})Implementations§
Source§impl<W: AsyncWrite, T, F: FnMut(StdWriteAdapter<'_, '_, Pin<&mut W>>) -> Poll<T>> StdWriteAdapterFuture<W, T, F>
impl<W: AsyncWrite, T, F: FnMut(StdWriteAdapter<'_, '_, Pin<&mut W>>) -> Poll<T>> StdWriteAdapterFuture<W, T, F>
Sourcepub fn new_assuming_correct_usage(writer: W, f: F) -> Self
pub fn new_assuming_correct_usage(writer: W, f: F) -> Self
Constructs the future.
It is required that the closure f only passes the writer given to it to functions that
guarantee correct restarting in case of WouldBlock errors. In particular, the write_all
method on the writer MUST NOT be called (it will panic) but also any other code that
behaves similarly by keeping the state on the stack and losing it if error happens (easy to
do by accident unless specific care was taken to avoid it).
Trait Implementations§
Source§impl<W: AsyncWrite, T, F: FnMut(StdWriteAdapter<'_, '_, Pin<&mut W>>) -> Poll<T>> Future for StdWriteAdapterFuture<W, T, F>
impl<W: AsyncWrite, T, F: FnMut(StdWriteAdapter<'_, '_, Pin<&mut W>>) -> Poll<T>> Future for StdWriteAdapterFuture<W, T, F>
impl<'__pin, W, T, F> Unpin for StdWriteAdapterFuture<W, T, F>where
PinnedFieldsOf<__Origin<'__pin, W, T, F>>: Unpin,
Auto Trait Implementations§
impl<W, T, F> Freeze for StdWriteAdapterFuture<W, T, F>
impl<W, T, F> RefUnwindSafe for StdWriteAdapterFuture<W, T, F>where
W: RefUnwindSafe,
F: RefUnwindSafe,
impl<W, T, F> Send for StdWriteAdapterFuture<W, T, F>
impl<W, T, F> Sync for StdWriteAdapterFuture<W, T, F>
impl<W, T, F> UnsafeUnpin for StdWriteAdapterFuture<W, T, F>where
W: UnsafeUnpin,
F: UnsafeUnpin,
impl<W, T, F> UnwindSafe for StdWriteAdapterFuture<W, T, F>where
W: UnwindSafe,
F: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn timeout(self, timeout: Duration) -> Timeout<Self>where
Self: Sized,
fn timeout(self, timeout: Duration) -> Timeout<Self>where
Self: Sized,
time only.tokio::time::timeout, with the advantage that it is easier to write
fluent call chains. Read moreSource§fn timeout_at(self, deadline: Instant) -> Timeout<Self>where
Self: Sized,
fn timeout_at(self, deadline: Instant) -> Timeout<Self>where
Self: Sized,
time only.tokio::time::timeout_at, with the advantage that it is easier to write
fluent call chains. Read moreSource§fn with_cancellation_token(
self,
cancellation_token: &CancellationToken,
) -> WithCancellationTokenFuture<'_, Self>where
Self: Sized,
fn with_cancellation_token(
self,
cancellation_token: &CancellationToken,
) -> WithCancellationTokenFuture<'_, Self>where
Self: Sized,
time only.CancellationToken::run_until_cancelled,
but with the advantage that it is easier to write fluent call chains. Read moreSource§fn with_cancellation_token_owned(
self,
cancellation_token: CancellationToken,
) -> WithCancellationTokenFutureOwned<Self>where
Self: Sized,
fn with_cancellation_token_owned(
self,
cancellation_token: CancellationToken,
) -> WithCancellationTokenFutureOwned<Self>where
Self: Sized,
time only.CancellationToken::run_until_cancelled_owned,
but with the advantage that it is easier to write fluent call chains. Read more§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn map<U, F>(self, f: F) -> Map<Self, F>
fn map<U, F>(self, f: F) -> Map<Self, F>
§fn map_into<U>(self) -> MapInto<Self, U>
fn map_into<U>(self) -> MapInto<Self, U>
§fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
f. Read more§fn left_future<B>(self) -> Either<Self, B>
fn left_future<B>(self) -> Either<Self, B>
§fn right_future<A>(self) -> Either<A, Self>
fn right_future<A>(self) -> Either<A, Self>
§fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
§fn flatten(self) -> Flatten<Self>
fn flatten(self) -> Flatten<Self>
§fn flatten_stream(self) -> FlattenStream<Self>
fn flatten_stream(self) -> FlattenStream<Self>
§fn fuse(self) -> Fuse<Self>where
Self: Sized,
fn fuse(self) -> Fuse<Self>where
Self: Sized,
poll will never again be called once it has
completed. This method can be used to turn any Future into a
FusedFuture. Read more§fn inspect<F>(self, f: F) -> Inspect<Self, F>
fn inspect<F>(self, f: F) -> Inspect<Self, F>
§fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
std only.std, or crate features alloc and spin only.§fn remote_handle(self) -> (Remote<Self>, RemoteHandle<Self::Output>)where
Self: Sized,
fn remote_handle(self) -> (Remote<Self>, RemoteHandle<Self::Output>)where
Self: Sized,
channel only.() on completion and sends
its output to another future on a separate task. Read more§fn boxed<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'a>>
fn boxed<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'a>>
alloc only.§fn boxed_local<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + 'a>>where
Self: Sized + 'a,
fn boxed_local<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + 'a>>where
Self: Sized + 'a,
alloc only.§fn unit_error(self) -> UnitError<Self>where
Self: Sized,
fn unit_error(self) -> UnitError<Self>where
Self: Sized,
Future<Output = T> into a
TryFuture<Ok = T, Error = ()>.§fn never_error(self) -> NeverError<Self>where
Self: Sized,
fn never_error(self) -> NeverError<Self>where
Self: Sized,
Future<Output = T> into a
TryFuture<Ok = T, Error = Never>.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<F> IntoFuture for Fwhere
F: Future,
impl<F> IntoFuture for Fwhere
F: Future,
Source§type IntoFuture = F
type IntoFuture = F
Source§fn into_future(self) -> <F as IntoFuture>::IntoFuture
fn into_future(self) -> <F as IntoFuture>::IntoFuture
§impl<F, T, E> TryFuture for F
impl<F, T, E> TryFuture for F
§impl<Fut> TryFutureExt for Futwhere
Fut: TryFuture + ?Sized,
impl<Fut> TryFutureExt for Futwhere
Fut: TryFuture + ?Sized,
§fn flatten_sink<Item>(self) -> FlattenSink<Self, Self::Ok>where
Self::Ok: Sink<Item, Error = Self::Error>,
Self: Sized,
fn flatten_sink<Item>(self) -> FlattenSink<Self, Self::Ok>where
Self::Ok: Sink<Item, Error = Self::Error>,
Self: Sized,
sink only.Sink]. Read more