1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright © 2024 PDF Composer (pdf_composer). All rights reserved.
// SPDX-License-Identifier: Apache-2.0 OR MIT
use ;
use ;
/// This function reads the lines of a file and returns an iterator over the lines.
///
/// # Arguments
///
/// * `filename` - A value that implements the `AsRef<Path>` trait, which represents the path
/// to the file to be read. This could be a `String`, `&str`, or `PathBuf`.
///
/// # Returns
///
/// * `Ok(Lines<BufReader<File>>)` - An iterator over the lines of the file, wrapped in a `BufReader`
/// for efficient reading.
/// * `Err(e)` - An error if the file cannot be opened, where `e` is an instance of `std::io::Error`.
///
/// # Remarks
///
/// This function uses the `std::fs::File` module to open the file specified by `filename`.
/// If the file is successfully opened, it creates a `BufReader` instance around the file,
/// which provides buffered reading capabilities for improved performance.
///
/// The `lines()` method is then called on the `BufReader`, which returns an iterator over
/// the lines of the file. Each line is returned as a `Result<String>`, where an `Err` value
/// indicates an error reading the line (e.g., an invalid UTF-8 encoding).
///
/// # Examples
///
/// ```
/// use std::path::Path;
///
/// // Define the path to the file
/// let file_path = Path::new("example.txt");
///
/// // Read lines from the file
/// match read_lines(file_path) {
/// Ok(lines) => {
/// // Iterate over the lines and print them
/// for line in lines {
/// if let Ok(line) = line {
/// println!("{}", line);
/// }
/// }
/// }
/// Err(err) => {
/// eprintln!("Error reading file: {}", err);
/// }
/// }
/// ```