From c4567f741a945d308c5cd54bdcc3872b905b65ae Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Wed, 25 Sep 2019 22:17:43 +0900 Subject: [PATCH] io: add get_*/into_inner methods to BufStream (#1598) --- tokio-io/src/io/buf_stream.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tokio-io/src/io/buf_stream.rs b/tokio-io/src/io/buf_stream.rs index 5ffe15e9d..6ec03effb 100644 --- a/tokio-io/src/io/buf_stream.rs +++ b/tokio-io/src/io/buf_stream.rs @@ -25,6 +25,34 @@ impl BufStream { pub fn new(stream: RW) -> BufStream { BufStream(BufReader::new(BufWriter::new(stream))) } + + /// Gets a reference to the underlying I/O object. + /// + /// It is inadvisable to directly read from the underlying I/O object. + pub fn get_ref(&self) -> &RW { + self.0.get_ref().get_ref() + } + + /// Gets a mutable reference to the underlying I/O object. + /// + /// It is inadvisable to directly read from the underlying I/O object. + pub fn get_mut(&mut self) -> &mut RW { + self.0.get_mut().get_mut() + } + + /// Gets a pinned mutable reference to the underlying I/O object. + /// + /// It is inadvisable to directly read from the underlying I/O object. + pub fn get_pin_mut(self: Pin<&mut Self>) -> Pin<&mut RW> { + self.project().0.get_pin_mut().get_pin_mut() + } + + /// Consumes this `BufStream`, returning the underlying I/O object. + /// + /// Note that any leftover data in the internal buffer is lost. + pub fn into_inner(self) -> RW { + self.0.into_inner().into_inner() + } } impl AsyncWrite for BufStream {