Rust

Rust

Made by DeepSource

Found I/O operation with unhandled return value RS-E1023

Bug risk
Major

io::Write::write() and io::Read::read() 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.

Bad practice

use std::io;

fn foo<W: io::Write>(w: &mut W) -> io::Result<()> {
    w.write(b"foo")?;
    Ok(())
}

fn bar<R: io::Read>(r: &mut R) -> io::Result<()> {
    r.read("baz".to_bytes())?;
    Ok(())
}

Recommended

use std::io;

fn foo<W: io::Write>(w: &mut W) -> io::Result<()> {
    w.write_all(b"foo")?;
    Ok(())
}

fn bar<R: io::Read>(r: &mut R) -> io::Result<()> {
    r.read_exact("baz".to_bytes())?;
    Ok(())
}