Don't re-open temporary file.

`Write` is implemented on both `&NamedTemporaryFile` and `&File` so you don't
actually need a mutable reference. I wish there were a better way to do this but
such is life.
This commit is contained in:
Steven Allen 2016-11-03 20:21:31 -07:00
parent e70fdc63c8
commit c02d7693b2

View file

@ -27,9 +27,8 @@ use std::io::Error as IOError;
use tempfile::NamedTempFile; use tempfile::NamedTempFile;
pub fn edit_in_tmpfile_with_command(mut cmd: Command, s: &mut String) -> Result<bool, IOError> { pub fn edit_in_tmpfile_with_command(mut cmd: Command, s: &mut String) -> Result<bool, IOError> {
let file = try!(NamedTempFile::new()); let mut file = &try!(NamedTempFile::new());
let file_path = file.path(); let file_path = file.path();
let mut file = try!(file.reopen());
try!(file.write_all(&s.clone().into_bytes()[..])); try!(file.write_all(&s.clone().into_bytes()[..]));
try!(file.sync_data()); try!(file.sync_data());