RS.CLIPPY.UNBUFFERED_BYTES

Calling .bytes() is very inefficient when data is not in memory

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: unbuffered_bytes. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for calls to Read::bytes on types which don't implement BufRead.

Why is this bad?

The default implementation calls read for each byte, which can be very inefficient for data that's not in memory, such as File.

Example

use std::io::Read;
use std::fs::File;
let file = File::open("./bytes.txt").unwrap();
file.bytes();

Use instead:

use std::io::{BufReader, Read};
use std::fs::File;
let file = BufReader::new(std::fs::File::open("./bytes.txt").unwrap());
file.bytes();