Skip to content

Commit 16f5546

Browse files
Nemo157cramertj
authored andcommitted
Allow unsized writer for copy_{buf_}into
1 parent 2e8acea commit 16f5546

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

futures-util/src/io/copy_buf_into.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ use std::pin::Pin;
77
/// Future for the [`copy_buf_into`](super::AsyncBufReadExt::copy_buf_into) method.
88
#[derive(Debug)]
99
#[must_use = "futures do nothing unless you `.await` or poll them"]
10-
pub struct CopyBufInto<'a, R, W> {
10+
pub struct CopyBufInto<'a, R, W: ?Sized> {
1111
reader: R,
1212
writer: &'a mut W,
1313
amt: u64,
1414
}
1515

16-
impl<R: Unpin, W> Unpin for CopyBufInto<'_, R, W> {}
16+
impl<R: Unpin, W: ?Sized> Unpin for CopyBufInto<'_, R, W> {}
1717

18-
impl<R, W> CopyBufInto<'_, R, W> {
18+
impl<R, W: ?Sized> CopyBufInto<'_, R, W> {
1919
pub(super) fn new(reader: R, writer: &mut W) -> CopyBufInto<'_, R, W> {
2020
CopyBufInto {
2121
reader,
@@ -25,7 +25,7 @@ impl<R, W> CopyBufInto<'_, R, W> {
2525
}
2626
}
2727

28-
impl<R, W: Unpin> CopyBufInto<'_, R, W> {
28+
impl<R, W: Unpin + ?Sized> CopyBufInto<'_, R, W> {
2929
fn project<'b>(self: Pin<&'b mut Self>) -> (Pin<&'b mut R>, Pin<&'b mut W>, &'b mut u64) {
3030
unsafe {
3131
let this = self.get_unchecked_mut();
@@ -36,7 +36,7 @@ impl<R, W: Unpin> CopyBufInto<'_, R, W> {
3636

3737
impl<R, W> Future for CopyBufInto<'_, R, W>
3838
where R: AsyncBufRead,
39-
W: AsyncWrite + Unpin,
39+
W: AsyncWrite + Unpin + ?Sized,
4040
{
4141
type Output = io::Result<u64>;
4242

futures-util/src/io/copy_into.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ use pin_utils::unsafe_pinned;
99
/// Future for the [`copy_into`](super::AsyncReadExt::copy_into) method.
1010
#[derive(Debug)]
1111
#[must_use = "futures do nothing unless you `.await` or poll them"]
12-
pub struct CopyInto<'a, R: AsyncRead, W> {
12+
pub struct CopyInto<'a, R: AsyncRead, W: ?Sized> {
1313
inner: CopyBufInto<'a, BufReader<R>, W>,
1414
}
1515

16-
impl<'a, R: AsyncRead, W> Unpin for CopyInto<'a, R, W> where CopyBufInto<'a, BufReader<R>, W>: Unpin {}
16+
impl<'a, R: AsyncRead, W: ?Sized> Unpin for CopyInto<'a, R, W> where CopyBufInto<'a, BufReader<R>, W>: Unpin {}
1717

18-
impl<'a, R: AsyncRead, W> CopyInto<'a, R, W> {
18+
impl<'a, R: AsyncRead, W: ?Sized> CopyInto<'a, R, W> {
1919
unsafe_pinned!(inner: CopyBufInto<'a, BufReader<R>, W>);
2020

2121
pub(super) fn new(reader: R, writer: &mut W) -> CopyInto<'_, R, W> {
@@ -25,7 +25,7 @@ impl<'a, R: AsyncRead, W> CopyInto<'a, R, W> {
2525
}
2626
}
2727

28-
impl<R: AsyncRead, W: AsyncWrite + Unpin> Future for CopyInto<'_, R, W> {
28+
impl<R: AsyncRead, W: AsyncWrite + Unpin + ?Sized> Future for CopyInto<'_, R, W> {
2929
type Output = io::Result<u64>;
3030

3131
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {

futures-util/src/io/mod.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ pub trait AsyncReadExt: AsyncRead {
111111
/// assert_eq!(writer.into_inner(), [1, 2, 3, 4, 0]);
112112
/// # Ok::<(), Box<dyn std::error::Error>>(()) }).unwrap();
113113
/// ```
114-
fn copy_into<W: AsyncWrite + Unpin>(self, writer: &mut W) -> CopyInto<'_, Self, W> where Self: Sized {
114+
fn copy_into<W>(self, writer: &mut W) -> CopyInto<'_, Self, W>
115+
where
116+
Self: Sized,
117+
W: AsyncWrite + Unpin + ?Sized,
118+
{
115119
CopyInto::new(self, writer)
116120
}
117121

@@ -467,7 +471,11 @@ pub trait AsyncBufReadExt: AsyncBufRead {
467471
/// assert_eq!(writer.into_inner(), [1, 2, 3, 4, 0]);
468472
/// # Ok::<(), Box<dyn std::error::Error>>(()) }).unwrap();
469473
/// ```
470-
fn copy_buf_into<W: AsyncWrite + Unpin>(self, writer: &mut W) -> CopyBufInto<'_, Self, W> where Self: Sized {
474+
fn copy_buf_into<W>(self, writer: &mut W) -> CopyBufInto<'_, Self, W>
475+
where
476+
Self: Sized,
477+
W: AsyncWrite + Unpin + ?Sized,
478+
{
471479
CopyBufInto::new(self, writer)
472480
}
473481

0 commit comments

Comments
 (0)