Count lines in a file using a buffered reader without holding the entire file contents in memory.
(path: &Path)
| 58 | /// Count lines in a file using a buffered reader without holding the entire |
| 59 | /// file contents in memory. |
| 60 | fn count_lines(path: &Path) -> usize { |
| 61 | let Ok(file) = std::fs::File::open(path) else { |
| 62 | return 0; |
| 63 | }; |
| 64 | let reader = BufReader::new(file); |
| 65 | reader.lines().count() |
| 66 | } |