Add a utility read_to_string() function.

This commit is contained in:
Jakob Stoklund Olesen
2016-09-14 13:14:43 -07:00
parent ddadf2e7c1
commit 99c04383c8
5 changed files with 22 additions and 20 deletions

View File

@@ -3,11 +3,9 @@
//! Read a sequence of Cretonne IL files and print them again to stdout. This has the effect of
//! normalizing formatting and removing comments.
use std::fs::File;
use std::io::{self, Read};
use std::io;
use CommandResult;
use utils::read_to_string;
use cton_reader::parse_functions;
use cretonne::write::write_function;
@@ -22,10 +20,7 @@ pub fn run(files: Vec<String>) -> CommandResult {
}
fn cat_one(filename: String) -> CommandResult {
let mut file = try!(File::open(&filename).map_err(|e| format!("{}: {}", filename, e)));
let mut buffer = String::new();
try!(file.read_to_string(&mut buffer)
.map_err(|e| format!("Couldn't read {}: {}", filename, e)));
let buffer = try!(read_to_string(&filename).map_err(|e| format!("{}: {}", filename, e)));
let items = try!(parse_functions(&buffer).map_err(|e| format!("{}: {}", filename, e)));
for (idx, func) in items.into_iter().enumerate() {