]> git.lizzy.rs Git - rust.git/blob - src/docs/unused_io_amount.txt
Auto merge of #9421 - xphoniex:fix-#9420, r=giraffate
[rust.git] / src / docs / unused_io_amount.txt
1 ### What it does
2 Checks for unused written/read amount.
3
4 ### Why is this bad?
5 `io::Write::write(_vectored)` and
6 `io::Read::read(_vectored)` are not guaranteed to
7 process the entire buffer. They return how many bytes were processed, which
8 might be smaller
9 than a given buffer's length. If you don't need to deal with
10 partial-write/read, use
11 `write_all`/`read_exact` instead.
12
13 When working with asynchronous code (either with the `futures`
14 crate or with `tokio`), a similar issue exists for
15 `AsyncWriteExt::write()` and `AsyncReadExt::read()` : these
16 functions are also not guaranteed to process the entire
17 buffer.  Your code should either handle partial-writes/reads, or
18 call the `write_all`/`read_exact` methods on those traits instead.
19
20 ### Known problems
21 Detects only common patterns.
22
23 ### Examples
24 ```
25 use std::io;
26 fn foo<W: io::Write>(w: &mut W) -> io::Result<()> {
27     // must be `w.write_all(b"foo")?;`
28     w.write(b"foo")?;
29     Ok(())
30 }
31 ```