[solved] Confusion on Read::read docs

In the docs for the read method from the [Read][1] trait is the following paragraph:

fn read(&mut self, buf: &mut [u8]) -> Result


> No guarantees are provided about the contents of `buf` when this function is called, implementations cannot rely on any property of the contents of `buf` being true. It is recommended that implementations only write data to buf instead of reading its contents.

This confuses me greatly.  After reading data into a buffer, what else can I do with it, if I can't read it?  


  [1]: https://doc.rust-lang.org/nightly/std/io/trait.Read.html#tymethod.read

The key word is "implementations". This warning applies to all implementers of the Read trait, not consumers of the API:

impl Read for Something {
    fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
        // Do not read buf, only write to it.
    }
}
2 Likes

That makes perfect sense, thanks!