Skip to content

Commit 9a056ea

Browse files
najamelancramertj
authored andcommitted
Add AsyncWrite implementation for IntoAsyncRead
This implements AsyncWrite for IntoAsyncRead when the inner stream implements it, forwarding all method calls. This allows working on Types that keep both impls, and allows framing them with codecs where those require both traits (like tokio codec).
1 parent af434e1 commit 9a056ea

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

futures-util/src/try_stream/into_async_read.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::try_stream::TryStreamExt;
22
use core::pin::Pin;
33
use futures_core::stream::TryStream;
44
use futures_core::task::{Context, Poll};
5-
use futures_io::{AsyncRead, AsyncBufRead};
5+
use futures_io::{AsyncRead, AsyncWrite, AsyncBufRead};
66
use std::cmp;
77
use std::io::{Error, Result};
88

@@ -100,6 +100,34 @@ where
100100
}
101101
}
102102

103+
impl<St> AsyncWrite for IntoAsyncRead<St>
104+
where
105+
St: TryStream<Error = Error> + AsyncWrite + Unpin,
106+
St::Ok: AsRef<[u8]>,
107+
{
108+
fn poll_write(
109+
mut self: Pin<&mut Self>,
110+
cx: &mut Context<'_>,
111+
buf: &[u8]
112+
) -> Poll<Result<usize>> {
113+
Pin::new( &mut self.stream ).poll_write( cx, buf )
114+
}
115+
116+
fn poll_flush(
117+
mut self: Pin<&mut Self>,
118+
cx: &mut Context<'_>
119+
) -> Poll<Result<()>> {
120+
Pin::new( &mut self.stream ).poll_flush( cx )
121+
}
122+
123+
fn poll_close(
124+
mut self: Pin<&mut Self>,
125+
cx: &mut Context<'_>
126+
) -> Poll<Result<()>> {
127+
Pin::new( &mut self.stream ).poll_close( cx )
128+
}
129+
}
130+
103131
impl<St> AsyncBufRead for IntoAsyncRead<St>
104132
where
105133
St: TryStream<Error = Error> + Unpin,

0 commit comments

Comments
 (0)