1use crate::io::AsyncWrite;
2
3use pin_project_lite::pin_project;
4use std::io;
5use std::marker::PhantomPinned;
6use std::pin::Pin;
7use std::task::{Context, Poll};
8use std::{future::Future, io::IoSlice};
9
10pin_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
23pub(crate) fn write_vectored<'a, 'b, W>(
24 writer: &'a mut W,
25 bufs: &'a [IoSlice<'b>],
26) -> WriteVectored<'a, 'b, W>
27where
28 W: AsyncWrite + Unpin + ?Sized,
29{
30 WriteVectored {
31 writer,
32 bufs,
33 _pin: PhantomPinned,
34 }
35}
36
37impl<W> Future for WriteVectored<'_, '_, W>
38where
39 W: AsyncWrite + Unpin + ?Sized,
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: Projection<'_, '_, '_, W> = self.project();
45 Pin::new(&mut *me.writer).poll_write_vectored(cx, me.bufs)
46 }
47}
48