about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-07-12 06:23:38 +0000
committerbors <bors@rust-lang.org>2017-07-12 06:23:38 +0000
commit8ac29bdd110b7f09b6ca6c0a1917d81285d64b3a (patch)
tree44aac4d2bd98e5f262dbd5585bafd2cb938e97c2 /src/libstd
parentd1f1f86d7f5b0ee363b3d247624c01db3b1ef55f (diff)
parent7109d03db50379c881b7efa42a46a8472c65f9a0 (diff)
downloadrust-8ac29bdd110b7f09b6ca6c0a1917d81285d64b3a.tar.gz
rust-8ac29bdd110b7f09b6ca6c0a1917d81285d64b3a.zip
Auto merge of #42697 - Mark-Simulacrum:take-limit, r=aturon
Allow setting the limit on std::io::Take.

Fixes https://github.com/rust-lang/rust/issues/27269.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/io/mod.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs
index 71c76008244..9a3036f753e 100644
--- a/src/libstd/io/mod.rs
+++ b/src/libstd/io/mod.rs
@@ -1755,6 +1755,35 @@ impl<T> Take<T> {
     #[stable(feature = "rust1", since = "1.0.0")]
     pub fn limit(&self) -> u64 { self.limit }
 
+    /// Sets the number of bytes that can be read before this instance will
+    /// return EOF. This is the same as constructing a new `Take` instance, so
+    /// the amount of bytes read and the previous limit value don't matter when
+    /// calling this method.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// #![feature(take_set_limit)]
+    /// use std::io;
+    /// use std::io::prelude::*;
+    /// use std::fs::File;
+    ///
+    /// # fn foo() -> io::Result<()> {
+    /// let f = File::open("foo.txt")?;
+    ///
+    /// // read at most five bytes
+    /// let mut handle = f.take(5);
+    /// handle.set_limit(10);
+    ///
+    /// assert_eq!(handle.limit(), 10);
+    /// # Ok(())
+    /// # }
+    /// ```
+    #[unstable(feature = "take_set_limit", issue = "42781")]
+    pub fn set_limit(&mut self, limit: u64) {
+        self.limit = limit;
+    }
+
     /// Consumes the `Take`, returning the wrapped reader.
     ///
     /// # Examples