]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/src/docs/unused_io_amount.txt
New upstream version 1.66.0+dfsg1
[rustc.git] / src / tools / clippy / src / docs / unused_io_amount.txt
CommitLineData
f2b60f7d
FG
1### What it does
2Checks 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
7process the entire buffer. They return how many bytes were processed, which
8might be smaller
9than a given buffer's length. If you don't need to deal with
10partial-write/read, use
11`write_all`/`read_exact` instead.
12
13When working with asynchronous code (either with the `futures`
14crate or with `tokio`), a similar issue exists for
15`AsyncWriteExt::write()` and `AsyncReadExt::read()` : these
16functions are also not guaranteed to process the entire
17buffer. Your code should either handle partial-writes/reads, or
18call the `write_all`/`read_exact` methods on those traits instead.
19
20### Known problems
21Detects only common patterns.
22
23### Examples
24```
25use std::io;
26fn 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```