20 lines
469 B
Rust
20 lines
469 B
Rust
use std::fs::File;
|
|
use std::io::{self, BufRead};
|
|
use std::path::Path;
|
|
|
|
pub fn read_lines<P>(filename: P) -> io::Result<io::Lines<io::BufReader<File>>>
|
|
where
|
|
P: AsRef<Path>,
|
|
{
|
|
let file = File::open(filename)?;
|
|
Ok(io::BufReader::new(file).lines())
|
|
}
|
|
|
|
pub fn read_without_lines<P>(filename: P) -> Result<String, io::Error>
|
|
where
|
|
P: AsRef<Path>,
|
|
{
|
|
let lines = read_lines(filename)?;
|
|
Ok(lines.fold(String::new(), |acc, line| acc + &line.unwrap()))
|
|
}
|