From a22f7a574cbbad22ed637405bafee42593eab87b Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 25 Jul 2020 17:39:38 +0200 Subject: Suggestion.apply(): Use `Suggestion.apply_to()` Replace common code with a call to `Suggestion.apply_to()`. --- src/lib.rs | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 34617d0..3b94993 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -121,27 +121,12 @@ impl Suggestion { fs::copy(repo_root.join(&self.path), new.path()).unwrap(); - let reader = BufReader::new(new); let mut original = OpenOptions::new() .write(true) .truncate(true) .open(repo_root.join(&self.path)).unwrap(); - for (i, line) in reader.lines().enumerate() { - match line { - Ok(l) => { - if i < self.original_start_line - || i > self.original_end_line { - writeln!(original, "{}", l).unwrap(); - } else if i == self.original_end_line { - write!(original, "{}", self.suggestion()).unwrap(); - } - }, - Err(e) => panic!(e), - } - } - - Ok(()) + self.apply_to(&mut original) } fn apply_to(&self, writer: &mut W) ->Result<(), Error> { -- cgit v1.2.3