Skip to content

Commit bfb76dd

Browse files
committed
Pass through AsyncBufRead trait
1 parent 535fc9c commit bfb76dd

File tree

8 files changed

+96
-4
lines changed

8 files changed

+96
-4
lines changed

src/futures/write/generic/decoder.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
util::PartialBuffer,
1111
};
1212
use futures_core::ready;
13-
use futures_io::{AsyncRead, AsyncWrite, IoSliceMut};
13+
use futures_io::{AsyncBufRead, AsyncRead, AsyncWrite, IoSliceMut};
1414
use pin_project_lite::pin_project;
1515

1616
#[derive(Debug)]
@@ -202,3 +202,13 @@ impl<W: AsyncRead, D> AsyncRead for Decoder<W, D> {
202202
self.get_pin_mut().poll_read_vectored(cx, bufs)
203203
}
204204
}
205+
206+
impl<W: AsyncBufRead, D> AsyncBufRead for Decoder<W, D> {
207+
fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<&[u8]>> {
208+
self.get_pin_mut().poll_fill_buf(cx)
209+
}
210+
211+
fn consume(self: Pin<&mut Self>, amt: usize) {
212+
self.get_pin_mut().consume(amt)
213+
}
214+
}

src/futures/write/generic/encoder.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
util::PartialBuffer,
1111
};
1212
use futures_core::ready;
13-
use futures_io::{AsyncRead, AsyncWrite, IoSliceMut};
13+
use futures_io::{AsyncBufRead, AsyncRead, AsyncWrite, IoSliceMut};
1414
use pin_project_lite::pin_project;
1515

1616
#[derive(Debug)]
@@ -199,3 +199,13 @@ impl<W: AsyncRead, E> AsyncRead for Encoder<W, E> {
199199
self.get_pin_mut().poll_read_vectored(cx, bufs)
200200
}
201201
}
202+
203+
impl<W: AsyncBufRead, E> AsyncBufRead for Encoder<W, E> {
204+
fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<&[u8]>> {
205+
self.get_pin_mut().poll_fill_buf(cx)
206+
}
207+
208+
fn consume(self: Pin<&mut Self>, amt: usize) {
209+
self.get_pin_mut().consume(amt)
210+
}
211+
}

src/futures/write/macros/decoder.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,19 @@ macro_rules! decoder {
9999
}
100100
}
101101

102+
impl<$inner: futures_io::AsyncBufRead> futures_io::AsyncBufRead for $name<$inner> {
103+
fn poll_fill_buf(
104+
self: std::pin::Pin<&mut Self>,
105+
cx: &mut std::task::Context<'_>
106+
) -> std::task::Poll<std::io::Result<&[u8]>> {
107+
self.get_pin_mut().poll_fill_buf(cx)
108+
}
109+
110+
fn consume(self: std::pin::Pin<&mut Self>, amt: usize) {
111+
self.get_pin_mut().consume(amt)
112+
}
113+
}
114+
102115
const _: () = {
103116
fn _assert() {
104117
use crate::util::{_assert_send, _assert_sync};

src/futures/write/macros/encoder.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,19 @@ macro_rules! encoder {
9696
}
9797
}
9898

99+
impl<$inner: futures_io::AsyncBufRead> futures_io::AsyncBufRead for $name<$inner> {
100+
fn poll_fill_buf(
101+
self: std::pin::Pin<&mut Self>,
102+
cx: &mut std::task::Context<'_>
103+
) -> std::task::Poll<std::io::Result<&[u8]>> {
104+
self.get_pin_mut().poll_fill_buf(cx)
105+
}
106+
107+
fn consume(self: std::pin::Pin<&mut Self>, amt: usize) {
108+
self.get_pin_mut().consume(amt)
109+
}
110+
}
111+
99112
const _: () = {
100113
fn _assert() {
101114
use crate::util::{_assert_send, _assert_sync};

src/tokio/write/generic/decoder.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{
1111
};
1212
use futures_core::ready;
1313
use pin_project_lite::pin_project;
14-
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
14+
use tokio::io::{AsyncBufRead, AsyncRead, AsyncWrite, ReadBuf};
1515

1616
#[derive(Debug)]
1717
enum State {
@@ -196,3 +196,13 @@ impl<W: AsyncRead, D> AsyncRead for Decoder<W, D> {
196196
self.get_pin_mut().poll_read(cx, buf)
197197
}
198198
}
199+
200+
impl<W: AsyncBufRead, D> AsyncBufRead for Decoder<W, D> {
201+
fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<&[u8]>> {
202+
self.get_pin_mut().poll_fill_buf(cx)
203+
}
204+
205+
fn consume(self: Pin<&mut Self>, amt: usize) {
206+
self.get_pin_mut().consume(amt)
207+
}
208+
}

src/tokio/write/generic/encoder.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{
1111
};
1212
use futures_core::ready;
1313
use pin_project_lite::pin_project;
14-
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
14+
use tokio::io::{AsyncBufRead, AsyncRead, AsyncWrite, ReadBuf};
1515

1616
#[derive(Debug)]
1717
enum State {
@@ -193,3 +193,13 @@ impl<W: AsyncRead, E> AsyncRead for Encoder<W, E> {
193193
self.get_pin_mut().poll_read(cx, buf)
194194
}
195195
}
196+
197+
impl<W: AsyncBufRead, E> AsyncBufRead for Encoder<W, E> {
198+
fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<&[u8]>> {
199+
self.get_pin_mut().poll_fill_buf(cx)
200+
}
201+
202+
fn consume(self: Pin<&mut Self>, amt: usize) {
203+
self.get_pin_mut().consume(amt)
204+
}
205+
}

src/tokio/write/macros/decoder.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,19 @@ macro_rules! decoder {
9191
}
9292
}
9393

94+
impl<$inner: tokio::io::AsyncBufRead> tokio::io::AsyncBufRead for $name<$inner> {
95+
fn poll_fill_buf(
96+
self: std::pin::Pin<&mut Self>,
97+
cx: &mut std::task::Context<'_>
98+
) -> std::task::Poll<std::io::Result<&[u8]>> {
99+
self.get_pin_mut().poll_fill_buf(cx)
100+
}
101+
102+
fn consume(self: std::pin::Pin<&mut Self>, amt: usize) {
103+
self.get_pin_mut().consume(amt)
104+
}
105+
}
106+
94107
const _: () = {
95108
fn _assert() {
96109
use crate::util::{_assert_send, _assert_sync};

src/tokio/write/macros/encoder.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,19 @@ macro_rules! encoder {
8888
}
8989
}
9090

91+
impl<$inner: tokio::io::AsyncBufRead> tokio::io::AsyncBufRead for $name<$inner> {
92+
fn poll_fill_buf(
93+
self: std::pin::Pin<&mut Self>,
94+
cx: &mut std::task::Context<'_>
95+
) -> std::task::Poll<std::io::Result<&[u8]>> {
96+
self.get_pin_mut().poll_fill_buf(cx)
97+
}
98+
99+
fn consume(self: std::pin::Pin<&mut Self>, amt: usize) {
100+
self.get_pin_mut().consume(amt)
101+
}
102+
}
103+
91104
const _: () = {
92105
fn _assert() {
93106
use crate::util::{_assert_send, _assert_sync};

0 commit comments

Comments
 (0)