RS.CLIPPY.UNUSED_IO_AMOUNT
Unused written/read amount
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: unused_io_amount. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for unused written/read amount.
Why is this bad?
io::Write::write(_vectored) and
io::Read::read(_vectored) are not guaranteed to
process the entire buffer. They return how many bytes were processed, which
might be smaller
than a given buffer's length. If you don't need to deal with
partial-write/read, use
write_all/read_exact instead.
When working with asynchronous code (either with the futures
crate or with tokio), a similar issue exists for
AsyncWriteExt::write() and AsyncReadExt::read() : these
functions are also not guaranteed to process the entire
buffer. Your code should either handle partial-writes/reads, or
call the write_all/read_exact methods on those traits instead.
Known problems
Detects only common patterns.
Examples
use std::io;
fn foo<W: io::Write>(w: &mut W) -> io::Result<()> {
w.write(b"foo")?;
Ok(())
}
Use instead:
use std::io;
fn foo<W: io::Write>(w: &mut W) -> io::Result<()> {
w.write_all(b"foo")?;
Ok(())
}