cryptopals-rust/src/io.rs
2019-08-31 10:14:30 +02:00

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()))
}