Read bytes using new IO


I’m trying out the new IO API. My old code used the methods Reader::read_exact and Reader::read_byte, that return IoResult<Vec<u8>> and IoResult<u8>. These are exactly the signatures I needed in my code.

Now, I could not find a replacement for these functions in the new IO API. I came up with these implementations:

impl<T:Read> MyReadExt for T {

    fn read_exact(&mut self, n: u64) -> io::Result<Vec<u8>> {
        let mut buf = vec![];
        try!(io::copy(&mut self.take(n), &mut buf));

    fn read_byte(&mut self) -> io::Result<u8> {
        try!(self.bytes().next().ok_or(io::Error::new(io::ErrorKind::Other, "EOF", None)))


These solutions are verbose compared to the old API. Did I overlook an alternative, easier solution to implement these functions ? Is the IO API too young for now and will eventually grow such convenience functions ?


These functions were removed in part to allow their design to iterate in; see the RFC for details. We wanted to keep the commitments of the core APIs slim, and let the broader ecosystem work on abstractions over it (which can eventually be incorporated).


I don’t see where that (the functions’ designs will be iterated in was mentioned in the RFC. Could you clarify?


It’s there: “Such a framework is out of scope for this RFC, but the endian-sensitive functionality will be provided elsewhere (likely out of tree).”