]> git.proxmox.com Git - rustc.git/blob - src/tools/clippy/src/docs/verbose_file_reads.txt
New upstream version 1.66.0+dfsg1
[rustc.git] / src / tools / clippy / src / docs / verbose_file_reads.txt
1 ### What it does
2 Checks for use of File::read_to_end and File::read_to_string.
3
4 ### Why is this bad?
5 `fs::{read, read_to_string}` provide the same functionality when `buf` is empty with fewer imports and no intermediate values.
6 See also: [fs::read docs](https://doc.rust-lang.org/std/fs/fn.read.html), [fs::read_to_string docs](https://doc.rust-lang.org/std/fs/fn.read_to_string.html)
7
8 ### Example
9 ```
10 let mut f = File::open("foo.txt").unwrap();
11 let mut bytes = Vec::new();
12 f.read_to_end(&mut bytes).unwrap();
13 ```
14 Can be written more concisely as
15 ```
16 let mut bytes = fs::read("foo.txt").unwrap();
17 ```