File tree 1 file changed +19
-0
lines changed
1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -576,6 +576,25 @@ impl<W: Write> BufWriter<W> {
576
576
& self . buf
577
577
}
578
578
579
+ /// Returns the number of bytes the internal buffer can hold without flushing.
580
+ ///
581
+ /// # Examples
582
+ ///
583
+ /// ```no_run
584
+ /// use std::io::BufWriter;
585
+ /// use std::net::TcpStream;
586
+ ///
587
+ /// let buf_writer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap());
588
+ ///
589
+ /// // Check the capacity of the inner buffer
590
+ /// let capacity = buf_writer.capacity();
591
+ /// // Calculate how many bytes can be written without flushing
592
+ /// let without_flush = capacity - buf_writer.buffer().len();
593
+ /// ```
594
+ pub fn capacity ( & self ) -> usize {
595
+ self . buf . capacity ( )
596
+ }
597
+
579
598
/// Unwraps this `BufWriter<W>`, returning the underlying writer.
580
599
///
581
600
/// The buffer is written out before returning the writer.
You can’t perform that action at this time.
0 commit comments