| 1 | use crate::io::AsyncWrite; |
| 2 | use futures_core::future::Future; |
| 3 | use futures_core::task::{Context, Poll}; |
| 4 | use std::io; |
| 5 | use std::pin::Pin; |
| 6 | |
| 7 | /// Future for the [`write`](super::AsyncWriteExt::write) method. |
| 8 | #[derive (Debug)] |
| 9 | #[must_use = "futures do nothing unless you `.await` or poll them" ] |
| 10 | pub struct Write<'a, W: ?Sized> { |
| 11 | writer: &'a mut W, |
| 12 | buf: &'a [u8], |
| 13 | } |
| 14 | |
| 15 | impl<W: ?Sized + Unpin> Unpin for Write<'_, W> {} |
| 16 | |
| 17 | impl<'a, W: AsyncWrite + ?Sized + Unpin> Write<'a, W> { |
| 18 | pub(super) fn new(writer: &'a mut W, buf: &'a [u8]) -> Self { |
| 19 | Self { writer, buf } |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | impl<W: AsyncWrite + ?Sized + Unpin> Future for Write<'_, W> { |
| 24 | type Output = io::Result<usize>; |
| 25 | |
| 26 | fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { |
| 27 | let this: &mut Write<'_, W> = &mut *self; |
| 28 | Pin::new(&mut this.writer).poll_write(cx, this.buf) |
| 29 | } |
| 30 | } |
| 31 | |