From 1448bec785c3bf56ee426ebe2728a29d79fa3624 Mon Sep 17 00:00:00 2001 From: gwo Date: Sun, 31 Mar 2024 23:59:52 +0800 Subject: [PATCH] Make non constructor methods of futures::io::{BufReader,BufWriter} not require inner trait bound (#2848) --- futures-util/src/io/buf_reader.rs | 2 ++ futures-util/src/io/buf_writer.rs | 38 ++++++++++++++++--------------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/futures-util/src/io/buf_reader.rs b/futures-util/src/io/buf_reader.rs index d017b1f94..ec6a8e154 100644 --- a/futures-util/src/io/buf_reader.rs +++ b/futures-util/src/io/buf_reader.rs @@ -55,7 +55,9 @@ impl BufReader { Self { inner, buffer: buffer.into_boxed_slice(), pos: 0, cap: 0 } } } +} +impl BufReader { delegate_access_inner!(inner, R, ()); /// Returns a reference to the internally buffered data. diff --git a/futures-util/src/io/buf_writer.rs b/futures-util/src/io/buf_writer.rs index e0037262b..ddcf5e1b4 100644 --- a/futures-util/src/io/buf_writer.rs +++ b/futures-util/src/io/buf_writer.rs @@ -79,6 +79,26 @@ impl BufWriter { Poll::Ready(ret) } + /// Write directly using `inner`, bypassing buffering + pub(super) fn inner_poll_write( + self: Pin<&mut Self>, + cx: &mut Context<'_>, + buf: &[u8], + ) -> Poll> { + self.project().inner.poll_write(cx, buf) + } + + /// Write directly using `inner`, bypassing buffering + pub(super) fn inner_poll_write_vectored( + self: Pin<&mut Self>, + cx: &mut Context<'_>, + bufs: &[IoSlice<'_>], + ) -> Poll> { + self.project().inner.poll_write_vectored(cx, bufs) + } +} + +impl BufWriter { delegate_access_inner!(inner, W, ()); /// Returns a reference to the internally buffered data. @@ -131,24 +151,6 @@ impl BufWriter { this.buf.set_len(old_len + buf_len); } } - - /// Write directly using `inner`, bypassing buffering - pub(super) fn inner_poll_write( - self: Pin<&mut Self>, - cx: &mut Context<'_>, - buf: &[u8], - ) -> Poll> { - self.project().inner.poll_write(cx, buf) - } - - /// Write directly using `inner`, bypassing buffering - pub(super) fn inner_poll_write_vectored( - self: Pin<&mut Self>, - cx: &mut Context<'_>, - bufs: &[IoSlice<'_>], - ) -> Poll> { - self.project().inner.poll_write_vectored(cx, bufs) - } } impl AsyncWrite for BufWriter {