Skip to content

Commit 75ce0af

Browse files
committed
generic tokio bufread encoder
1 parent ec3b6e8 commit 75ce0af

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

src/tokio/bufread/generic/decoder.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,32 +163,32 @@ impl<R: AsyncBufRead, D: Decode> AsyncRead for Decoder<R, D> {
163163
}
164164
}
165165

166-
impl<R: AsyncBufRead + AsyncWrite, D: Decode> AsyncWrite for Decoder<R, D> {
166+
impl<R: AsyncWrite, D: Decode> AsyncWrite for Decoder<R, D> {
167167
fn poll_write(
168168
mut self: Pin<&mut Self>,
169169
cx: &mut Context<'_>,
170170
buf: &[u8],
171171
) -> Poll<Result<usize>> {
172-
self.get_pin_mut().poll_write(cx, buf)
172+
self.project().reader.poll_write(cx, buf)
173173
}
174174

175175
fn poll_write_vectored(
176176
mut self: Pin<&mut Self>,
177177
cx: &mut Context<'_>,
178178
mut bufs: &[IoSlice<'_>],
179179
) -> Poll<Result<usize>> {
180-
self.get_pin_mut().poll_write_vectored(cx, bufs)
180+
self.project().reader.poll_write_vectored(cx, bufs)
181181
}
182182

183183
fn is_write_vectored(&self) -> bool {
184-
self.get_ref().is_write_vectored()
184+
self.reader.is_write_vectored()
185185
}
186186

187187
fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>> {
188-
self.get_pin_mut().poll_flush(cx)
188+
self.project().reader.poll_flush(cx)
189189
}
190190

191191
fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>> {
192-
self.get_pin_mut().poll_shutdown(cx)
192+
self.project().reader.poll_shutdown(cx)
193193
}
194194
}

src/tokio/bufread/generic/encoder.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ use core::{
22
pin::Pin,
33
task::{Context, Poll},
44
};
5-
use std::io::Result;
5+
use std::io::{IoSlice, Result};
66

77
use crate::{codec::Encode, util::PartialBuffer};
88
use futures_core::ready;
99
use pin_project_lite::pin_project;
10-
use tokio::io::{AsyncBufRead, AsyncRead, ReadBuf};
10+
use tokio::io::{AsyncBufRead, AsyncRead, AsyncWrite, ReadBuf};
1111

1212
#[derive(Debug)]
1313
enum State {
@@ -119,3 +119,33 @@ impl<R: AsyncBufRead, E: Encode> AsyncRead for Encoder<R, E> {
119119
}
120120
}
121121
}
122+
123+
impl<R: AsyncWrite, E: Encode> AsyncWrite for Encoder<R, E> {
124+
fn poll_write(
125+
mut self: Pin<&mut Self>,
126+
cx: &mut Context<'_>,
127+
buf: &[u8],
128+
) -> Poll<Result<usize>> {
129+
self.project().reader.poll_write(cx, buf)
130+
}
131+
132+
fn poll_write_vectored(
133+
mut self: Pin<&mut Self>,
134+
cx: &mut Context<'_>,
135+
mut bufs: &[IoSlice<'_>],
136+
) -> Poll<Result<usize>> {
137+
self.project().reader.poll_write_vectored(cx, bufs)
138+
}
139+
140+
fn is_write_vectored(&self) -> bool {
141+
self.reader.is_write_vectored()
142+
}
143+
144+
fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>> {
145+
self.project().reader.poll_flush(cx)
146+
}
147+
148+
fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>> {
149+
self.project().reader.poll_shutdown(cx)
150+
}
151+
}

0 commit comments

Comments
 (0)