Add a utility read_to_string() function.

This commit is contained in:
Jakob Stoklund Olesen
2016-09-14 13:14:43 -07:00
parent 4521afd474
commit 480054a094
5 changed files with 22 additions and 20 deletions

13
src/tools/utils.rs Normal file
View File

@@ -0,0 +1,13 @@
//! Utility functions.
use std::path::Path;
use std::fs::File;
use std::io::{Result, Read};
/// Read an entire file into a string.
pub fn read_to_string<P: AsRef<Path>>(path: P) -> Result<String> {
let mut file = try!(File::open(path));
let mut buffer = String::new();
try!(file.read_to_string(&mut buffer));
Ok(buffer)
}