Skip to content

Commit 2e8acea

Browse files
Nemo157cramertj
authored andcommitted
Change copy_into/copy_buf_into back to taking writer by reference
1 parent 9002b41 commit 2e8acea

File tree

3 files changed

+20
-24
lines changed

3 files changed

+20
-24
lines changed

futures-util/src/io/copy_buf_into.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,36 @@ 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<R, W> {
10+
pub struct CopyBufInto<'a, R, W> {
1111
reader: R,
12-
writer: W,
12+
writer: &'a mut W,
1313
amt: u64,
1414
}
1515

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

18-
impl<R, W> CopyBufInto<R, W> {
19-
pub(super) fn new(reader: R, writer: W) -> Self {
18+
impl<R, W> CopyBufInto<'_, R, W> {
19+
pub(super) fn new(reader: R, writer: &mut W) -> CopyBufInto<'_, R, W> {
2020
CopyBufInto {
2121
reader,
2222
writer,
2323
amt: 0,
2424
}
2525
}
26+
}
2627

27-
fn project<'a>(self: Pin<&'a mut Self>) -> (Pin<&'a mut R>, Pin<&'a mut W>, &'a mut u64) {
28+
impl<R, W: Unpin> CopyBufInto<'_, R, W> {
29+
fn project<'b>(self: Pin<&'b mut Self>) -> (Pin<&'b mut R>, Pin<&'b mut W>, &'b mut u64) {
2830
unsafe {
2931
let this = self.get_unchecked_mut();
30-
(Pin::new_unchecked(&mut this.reader), Pin::new_unchecked(&mut this.writer), &mut this.amt)
32+
(Pin::new_unchecked(&mut this.reader), Pin::new(&mut *this.writer), &mut this.amt)
3133
}
3234
}
3335
}
3436

35-
impl<R, W> Future for CopyBufInto<R, W>
37+
impl<R, W> Future for CopyBufInto<'_, R, W>
3638
where R: AsyncBufRead,
37-
W: AsyncWrite,
39+
W: AsyncWrite + Unpin,
3840
{
3941
type Output = io::Result<u64>;
4042

futures-util/src/io/copy_into.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@ 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<R: AsyncRead, W> {
13-
inner: CopyBufInto<BufReader<R>, W>,
12+
pub struct CopyInto<'a, R: AsyncRead, W> {
13+
inner: CopyBufInto<'a, BufReader<R>, W>,
1414
}
1515

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

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

21-
pub(super) fn new(reader: R, writer: W) -> Self {
21+
pub(super) fn new(reader: R, writer: &mut W) -> CopyInto<'_, R, W> {
2222
CopyInto {
2323
inner: CopyBufInto::new(BufReader::new(reader), writer),
2424
}
2525
}
2626
}
2727

28-
impl<R: AsyncRead, W: AsyncWrite> Future for CopyInto<R, W> {
28+
impl<R: AsyncRead, W: AsyncWrite + Unpin> 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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,6 @@ pub trait AsyncReadExt: AsyncRead {
9393
///
9494
/// On success the number of bytes is returned.
9595
///
96-
/// Note that this method consumes `writer` but does not close it, you will likely want to pass
97-
/// it by reference as shown in the example.
98-
///
9996
/// # Examples
10097
///
10198
/// ```
@@ -114,7 +111,7 @@ pub trait AsyncReadExt: AsyncRead {
114111
/// assert_eq!(writer.into_inner(), [1, 2, 3, 4, 0]);
115112
/// # Ok::<(), Box<dyn std::error::Error>>(()) }).unwrap();
116113
/// ```
117-
fn copy_into<W: AsyncWrite>(self, writer: W) -> CopyInto<Self, W> where Self: Sized {
114+
fn copy_into<W: AsyncWrite + Unpin>(self, writer: &mut W) -> CopyInto<'_, Self, W> where Self: Sized {
118115
CopyInto::new(self, writer)
119116
}
120117

@@ -452,9 +449,6 @@ pub trait AsyncBufReadExt: AsyncBufRead {
452449
///
453450
/// On success the number of bytes is returned.
454451
///
455-
/// Note that this method consumes `writer` but does not close it, you will likely want to pass
456-
/// it by reference as shown in the example.
457-
///
458452
/// # Examples
459453
///
460454
/// ```
@@ -473,7 +467,7 @@ pub trait AsyncBufReadExt: AsyncBufRead {
473467
/// assert_eq!(writer.into_inner(), [1, 2, 3, 4, 0]);
474468
/// # Ok::<(), Box<dyn std::error::Error>>(()) }).unwrap();
475469
/// ```
476-
fn copy_buf_into<W: AsyncWrite>(self, writer: W) -> CopyBufInto<Self, W> where Self: Sized {
470+
fn copy_buf_into<W: AsyncWrite + Unpin>(self, writer: &mut W) -> CopyBufInto<'_, Self, W> where Self: Sized {
477471
CopyBufInto::new(self, writer)
478472
}
479473

0 commit comments

Comments
 (0)