easier 0.3.0

making rust easier
Documentation
use std::{
    fs::File,
    io::{BufRead, BufReader},
    path::Path,
};

/// Opens a file and iterates through, reading line by line.
/// This exludes newline characters from the output
/// Easy way to read file in one line
/// ## Example
/// ```no_run
/// for line in easier::io::lines("/path/to/file.txt"){
///     print!("{line}")
/// }
/// ```
/// # Panics
/// - If the file does not exist
/// - If cannot read the file

pub fn lines<P: AsRef<Path>>(path: P) -> impl Iterator<Item = String> {
    let file = File::open(&path);

    match file {
        Ok(f) => LineIterator {
            rd: BufReader::new(f).lines(),
        },
        Err(err) => panic!(
            "Error opening {}: {err}",
            path.as_ref().as_os_str().to_string_lossy()
        ),
    }
}

struct LineIterator {
    rd: std::io::Lines<BufReader<File>>,
}

impl Iterator for LineIterator {
    type Item = String;

    fn next(&mut self) -> Option<Self::Item> {
        match self.rd.next() {
            Some(res2) => {
                match res2 {
                    Ok(str) => Some(str),                 //all ok
                    Err(_) => panic!("Cannot read file"), //reading file error
                }
            }
            None => None, //end of iterator
        }
    }
}