use top level fs
functions where appropriate
This commit replaces many usages of `File::open` and reading or writing with `fs::read_to_string`, `fs::read` and `fs::write`. This reduces code complexity, and will improve performance for most reads, since the functions allocate the buffer to be the size of the file. I believe that this commit will not impact behavior in any way, so some matches will check the error kind in case the file was not valid UTF-8. Some of these cases may not actually care about the error.
This commit is contained in:
parent
1c3236afc3
commit
2f6226518b
26 changed files with 137 additions and 235 deletions
|
@ -31,7 +31,7 @@ use std::path::{Path, PathBuf};
|
|||
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::io::{self, Read};
|
||||
use std::io;
|
||||
use errors::SourceMapper;
|
||||
|
||||
/// Return the span itself if it doesn't come from a macro expansion,
|
||||
|
@ -96,9 +96,7 @@ impl FileLoader for RealFileLoader {
|
|||
}
|
||||
|
||||
fn read_file(&self, path: &Path) -> io::Result<String> {
|
||||
let mut src = String::new();
|
||||
fs::File::open(path)?.read_to_string(&mut src)?;
|
||||
Ok(src)
|
||||
fs::read_to_string(path)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue