use fmt;
use int;
use iter::{Iterator, IteratorExt};
-use marker::Sized;
+use marker::{Sized, Send};
use mem::transmute;
use ops::FnOnce;
use option::Option;
}
}
-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
}
}
/// 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
/// }
///
/// // 'stream' is still available for use here
-///
-/// # }
/// ```
pub struct RefReader<'a, R:'a> {
/// The underlying reader which this is referencing
/// # 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();
///
/// {
/// }
///
/// println!("input processed: {:?}", output);
-/// # }
/// ```
pub struct RefWriter<'a, W:'a> {
/// The underlying writer which this is referencing
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.
/// 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 {