1 use crate::io::AsyncWrite;
2
3 use pin_project_lite::pin_project;
4 use std::io;
5 use std::marker::PhantomPinned;
6 use std::pin::Pin;
7 use std::task::{Context, Poll};
8 use std::{future::Future, io::IoSlice};
9
10 pin_project! {
11 /// A future to write a slice of buffers to an `AsyncWrite`.
12 #[derive(Debug)]
13 #[must_use = "futures do nothing unless you `.await` or poll them"]
14 pub struct WriteVectored<'a, 'b, W: ?Sized> {
15 writer: &'a mut W,
16 bufs: &'a [IoSlice<'b>],
17 // Make this future `!Unpin` for compatibility with async trait methods.
18 #[pin]
19 _pin: PhantomPinned,
20 }
21 }
22
write_all<'a, W>(writer: &'a mut W, buf: &'a [u8]) -> WriteAll<'a, W> where W: AsyncWrite + Unpin + ?Sized,23 pub(crate) fn write_vectored<'a, 'b, W>(
24 writer: &'a mut W,
25 bufs: &'a [IoSlice<'b>],
26 ) -> WriteVectored<'a, 'b, W>
27 where
28 W: AsyncWrite + Unpin + ?Sized,
29 {
30 WriteVectored {
31 writer,
32 bufs,
33 _pin: PhantomPinned,
34 }
35 }
36
37 impl<W> Future for WriteVectored<'_, '_, W>
38 where
39 W: AsyncWrite + Unpin + ?Sized,
poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>>40 {
41 type Output = io::Result<usize>;
42
43 fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<usize>> {
44 let me = self.project();
45 Pin::new(&mut *me.writer).poll_write_vectored(cx, me.bufs)
46 }
47 }
48