From c12001a574e7858060a91019dc28bdf137894065 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 24 Mar 2016 12:29:55 +0100 Subject: [PATCH] Remove unwraphell and replace by try!() --- libimagrt/src/edit.rs | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/libimagrt/src/edit.rs b/libimagrt/src/edit.rs index a34a4bf1..73529b53 100644 --- a/libimagrt/src/edit.rs +++ b/libimagrt/src/edit.rs @@ -37,24 +37,13 @@ pub fn edit_in_tmpfile(rt: &Runtime, s: &mut String) -> EditResult<()> { use std::io::SeekFrom; use std::io::Write; - let file = NamedTempFile::new(); - if file.is_err() { - return Err(RuntimeError::new(RuntimeErrorKind::Instantiate, None)); - } - let file = file.unwrap(); + let file = try!(NamedTempFile::new()); let file_path = file.path(); - let file = file.reopen(); + let mut file = try!(file.reopen()); - if file.is_err() { - return Err(RuntimeError::new(RuntimeErrorKind::IOError, Some(Box::new(file.err().unwrap())))); - } - - let mut file = file.unwrap(); file.write_all(&s.clone().into_bytes()[..]); - if let Err(e) = file.sync_data() { - return Err(RuntimeError::new(RuntimeErrorKind::IOError, Some(Box::new(e)))); - } + try!(file.sync_data()); if let Some(mut editor) = rt.editor() { let exit_status = editor.arg(file_path).status();