diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 9137068076b46..9749d549fd43e 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -213,6 +213,15 @@ pub trait Read { read_to_end(self, buf) } + /// Read all bytes until EOF in this source, returning them as a new `Vec`. + /// + /// See `read_to_end` for other semantics. + fn read_into_vec(&mut self) -> Result> { + let mut buf = Vec::new(); + let res = self.read_to_end(&mut buf); + res.map(|_| buf) + } + /// Read all bytes until EOF in this source, placing them into `buf`. /// /// # Errors @@ -233,6 +242,15 @@ pub trait Read { // know is guaranteed to only read data into the end of the buffer. append_to_string(buf, |b| read_to_end(self, b)) } + + /// Read all bytes until EOF in this source, returning them as a new buffer. + /// + /// See `read_to_string` for other semantics. + fn read_into_string(&mut self, buf: &mut String) -> Result { + let mut buf = String::new(); + let res = self.read_to_string(&mut buf); + res.map(|_| buf) + } } /// Extension methods for all instances of `Read`, typically imported through