File tree 1 file changed +25
-0
lines changed
1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -147,6 +147,31 @@ impl<R: Read> BufReader<R> {
147
147
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
148
148
pub fn get_mut ( & mut self ) -> & mut R { & mut self . inner }
149
149
150
+ /// Returns `true` if there are no bytes in the internal buffer.
151
+ ///
152
+ /// # Examples
153
+ /// ```
154
+ /// # #![feature(bufreader_is_empty)]
155
+ /// use std::io::BufReader;
156
+ /// use std::io::BufRead;
157
+ /// use std::fs::File;
158
+ ///
159
+ /// # fn foo() -> std::io::Result<()> {
160
+ /// let f1 = File::open("log.txt")?;
161
+ /// let mut reader = BufReader::new(f1);
162
+ /// assert!(reader.is_empty());
163
+ ///
164
+ /// if reader.fill_buf()?.len() > 0 {
165
+ /// assert!(!reader.is_empty());
166
+ /// }
167
+ /// # Ok(())
168
+ /// # }
169
+ /// ```
170
+ #[ unstable( feature = "bufreader_is_empty" , issue = "45323" , reason = "recently added" ) ]
171
+ pub fn is_empty ( & self ) -> bool {
172
+ self . pos == self . cap
173
+ }
174
+
150
175
/// Unwraps this `BufReader`, returning the underlying reader.
151
176
///
152
177
/// Note that any leftover data in the internal buffer is lost.
You can’t perform that action at this time.
0 commit comments