read_lines

Function read_lines 

Source
pub fn read_lines(path: impl AsRef<Path>) -> Result<Lines<BufReader<File>>>
Expand description

Reads the contents of a file line by line using buffered I/O.

This function opens the file at the specified path and returns an iterator over its lines, where each line is lazily read and returned as a Result<String, io::Error>. It utilizes a BufReader for efficient I/O operations.

§Parameters

  • path: The path to the file to be read. Accepts any type that implements AsRef<Path>.

§Returns

  • An Result containing an iterator over the lines of the file, where each line is represented as a Result<String, io::Error>.

§Examples

use regd_testing;

let lines = regd_testing::io::read_lines("Cargo.toml").expect("failed to open file");
for line in lines {
    let line = line.expect("failed to read line");
    println!("{}", line);
}