use futures_core::future::Future;
use futures_core::task::{Context, Poll};
use futures_io::{AsyncRead, AsyncWrite};
use std::io;
use std::pin::Pin;
use super::{BufReader, copy_buf, CopyBuf};
use pin_project_lite::pin_project;
pub fn copy<R, W>(reader: R, writer: &mut W) -> Copy<'_, R, W>
where
R: AsyncRead,
W: AsyncWrite + Unpin + ?Sized,
{
Copy {
inner: copy_buf(BufReader::new(reader), writer),
}
}
pin_project! {
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Copy<'a, R, W: ?Sized> {
#[pin]
inner: CopyBuf<'a, BufReader<R>, W>,
}
}
impl<R: AsyncRead, W: AsyncWrite + Unpin + ?Sized> Future for Copy<'_, R, W> {
type Output = io::Result<u64>;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
self.project().inner.poll(cx)
}
}