Minor tweaks

This commit is contained in:
Greg 2020-02-24 11:12:17 -05:00
parent 5f8b36596b
commit 5c1d60474e
No known key found for this signature in database
GPG key ID: 2E44FAEEDC94B1E2

View file

@ -86,11 +86,11 @@ impl Replacer {
} }
} }
fn replace_file(&self, path: impl AsRef<str>) -> Result<()> { fn replace_file(&self, path: &str) -> Result<()> {
use memmap::{Mmap, MmapMut}; use memmap::{Mmap, MmapMut};
use std::ops::DerefMut; use std::ops::DerefMut;
let path = std::path::Path::new(path.as_ref()); let path = std::path::Path::new(path);
let source = File::open(path)?; let source = File::open(path)?;
let meta = source.metadata()?; let meta = source.metadata()?;
let mmap_source = unsafe { Mmap::map(&source)? }; let mmap_source = unsafe { Mmap::map(&source)? };
@ -118,7 +118,7 @@ impl Replacer {
pub(crate) fn run(&self, source: &Source, in_place: bool) -> Result<()> { pub(crate) fn run(&self, source: &Source, in_place: bool) -> Result<()> {
match (source, in_place) { match (source, in_place) {
(Source::Stdin, _) => { (Source::Stdin, _) => {
let mut buffer = Vec::new(); let mut buffer = Vec::with_capacity(256);
let stdin = std::io::stdin(); let stdin = std::io::stdin();
let mut handle = stdin.lock(); let mut handle = stdin.lock();
handle.read_to_end(&mut buffer)?; handle.read_to_end(&mut buffer)?;