Reid/src/file_io.rs

15 lines
353 B
Rust

use std::fs::File;
use std::io::prelude::*;
use std::io::BufReader;
use std::path::Path;
use super::errors::GenericError;
pub fn open_file(path: &Path) -> Result<String, GenericError> {
let file = File::open(path)?;
let mut reader = BufReader::new(file);
let mut text = String::new();
reader.read_to_string(&mut text)?;
Ok(text)
}