Skip to content

Commit 662ac25

Browse files
committed
Expose buffer for LineWriter
1 parent e7d3f24 commit 662ac25

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

library/alloc/src/io/buffered/linewriter.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,24 @@ impl<W: Write> LineWriter<W> {
155155
self.inner.get_mut()
156156
}
157157

158+
/// Returns a reference to the internally buffered data.
159+
///
160+
/// # Examples
161+
///
162+
/// ```no_run
163+
/// use std::io::LineWriter;
164+
/// use std::net::TcpStream;
165+
///
166+
/// let buf_writer = LineWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap());
167+
///
168+
/// // See how many bytes are currently buffered
169+
/// let bytes_buffered = buf_writer.buffer().len();
170+
/// ```
171+
#[stable(feature = "rust1", since = "1.0.0")]
172+
pub fn buffer(&self) -> &[u8] {
173+
&self.inner.buffer()
174+
}
175+
158176
/// Unwraps this `LineWriter`, returning the underlying writer.
159177
///
160178
/// The internal buffer is written out before returning the writer.

0 commit comments

Comments
 (0)