1 use crate::io::AsyncWrite;
2 
3 use std::future::Future;
4 use std::io;
5 use std::pin::Pin;
6 use std::task::{Context, Poll};
7 
8 cfg_io_util! {
9     /// A future to write some of the buffer to an `AsyncWrite`.
10     #[derive(Debug)]
11     #[must_use = "futures do nothing unless you `.await` or poll them"]
12     pub struct Write<'a, W: ?Sized> {
13         writer: &'a mut W,
14         buf: &'a [u8],
15     }
16 }
17 
18 /// Tries to write some bytes from the given `buf` to the writer in an
19 /// asynchronous manner, returning a future.
write<'a, W>(writer: &'a mut W, buf: &'a [u8]) -> Write<'a, W> where W: AsyncWrite + Unpin + ?Sized,20 pub(crate) fn write<'a, W>(writer: &'a mut W, buf: &'a [u8]) -> Write<'a, W>
21 where
22     W: AsyncWrite + Unpin + ?Sized,
23 {
24     Write { writer, buf }
25 }
26 
27 impl<W> Future for Write<'_, W>
28 where
29     W: AsyncWrite + Unpin + ?Sized,
30 {
31     type Output = io::Result<usize>;
32 
poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<usize>>33     fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<usize>> {
34         let me = &mut *self;
35         Pin::new(&mut *me.writer).poll_write(cx, me.buf)
36     }
37 }
38