Add a utility read_to_string() function.
This commit is contained in:
13
src/tools/utils.rs
Normal file
13
src/tools/utils.rs
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user