]> git.lizzy.rs Git - rust.git/blobdiff - src/libstd/io/mod.rs
rollup merge of #21438: taralx/kill-racycell
[rust.git] / src / libstd / io / mod.rs
index bab4dafd090bdfc40ec6f90f5c2072744d16835d..a1a67ff051dc55a571577420e2f9f64a3c36f0f2 100644 (file)
 use fmt;
 use int;
 use iter::{Iterator, IteratorExt};
-use marker::Sized;
+use marker::{Sized, Send};
 use mem::transmute;
 use ops::FnOnce;
 use option::Option;
@@ -363,8 +363,8 @@ fn detail(&self) -> Option<String> {
     }
 }
 
-impl FromError<IoError> for Box<Error> {
-    fn from_error(err: IoError) -> Box<Error> {
+impl FromError<IoError> for Box<Error + Send> {
+    fn from_error(err: IoError) -> Box<Error + Send> {
         box err
     }
 }
@@ -934,16 +934,15 @@ unsafe fn slice_vec_capacity<'a, T>(v: &'a mut Vec<T>, start: uint, end: uint) -
 /// A `RefReader` is a struct implementing `Reader` which contains a reference
 /// to another reader. This is often useful when composing streams.
 ///
-/// # Example
+/// # Examples
 ///
 /// ```
-/// # fn main() {}
-/// # fn process_input<R: Reader>(r: R) {}
-/// # fn foo() {
 /// use std::io;
 /// use std::io::ByRefReader;
 /// use std::io::util::LimitReader;
 ///
+/// fn process_input<R: Reader>(r: R) {}
+///
 /// let mut stream = io::stdin();
 ///
 /// // Only allow the function to process at most one kilobyte of input
@@ -953,8 +952,6 @@ unsafe fn slice_vec_capacity<'a, T>(v: &'a mut Vec<T>, start: uint, end: uint) -
 /// }
 ///
 /// // 'stream' is still available for use here
-///
-/// # }
 /// ```
 pub struct RefReader<'a, R:'a> {
     /// The underlying reader which this is referencing
@@ -1269,12 +1266,11 @@ fn flush(&mut self) -> IoResult<()> { (**self).flush() }
 /// # Example
 ///
 /// ```
-/// # fn main() {}
-/// # fn process_input<R: Reader>(r: R) {}
-/// # fn foo () {
 /// use std::io::util::TeeReader;
 /// use std::io::{stdin, ByRefWriter};
 ///
+/// fn process_input<R: Reader>(r: R) {}
+///
 /// let mut output = Vec::new();
 ///
 /// {
@@ -1285,7 +1281,6 @@ fn flush(&mut self) -> IoResult<()> { (**self).flush() }
 /// }
 ///
 /// println!("input processed: {:?}", output);
-/// # }
 /// ```
 pub struct RefWriter<'a, W:'a> {
     /// The underlying writer which this is referencing
@@ -1441,33 +1436,31 @@ fn read_line(&mut self) -> IoResult<String> {
     fn read_until(&mut self, byte: u8) -> IoResult<Vec<u8>> {
         let mut res = Vec::new();
 
-        let mut used;
         loop {
-            {
+            let (done, used) = {
                 let available = match self.fill_buf() {
                     Ok(n) => n,
                     Err(ref e) if res.len() > 0 && e.kind == EndOfFile => {
-                        used = 0;
-                        break
+                        return Ok(res);
                     }
                     Err(e) => return Err(e)
                 };
                 match available.iter().position(|&b| b == byte) {
                     Some(i) => {
-                        res.push_all(&available[..(i + 1)]);
-                        used = i + 1;
-                        break
+                        res.push_all(&available[..i + 1]);
+                        (true, i + 1)
                     }
                     None => {
                         res.push_all(available);
-                        used = available.len();
+                        (false, available.len())
                     }
                 }
+            };
+            buffer.consume(used);
+            if done {
+                return Ok(res);
             }
-            self.consume(used);
         }
-        self.consume(used);
-        Ok(res)
     }
 
     /// Reads the next utf8-encoded character from the underlying stream.
@@ -1705,19 +1698,19 @@ pub enum FileType {
 /// A structure used to describe metadata information about a file. This
 /// structure is created through the `stat` method on a `Path`.
 ///
-/// # Example
+/// # Examples
+///
+/// ```no_run
+/// # #![allow(unstable)]
+///
+/// use std::io::fs::PathExtensions;
 ///
-/// ```
-/// # use std::io::fs::PathExtensions;
-/// # fn main() {}
-/// # fn foo() {
 /// let info = match Path::new("foo.txt").stat() {
 ///     Ok(stat) => stat,
 ///     Err(e) => panic!("couldn't read foo.txt: {}", e),
 /// };
 ///
 /// println!("byte size: {}", info.size);
-/// # }
 /// ```
 #[derive(Copy, Hash)]
 pub struct FileStat {