diff options
author | Teddy Wing | 2020-07-25 17:39:38 +0200 |
---|---|---|
committer | Teddy Wing | 2020-07-25 17:39:38 +0200 |
commit | a22f7a574cbbad22ed637405bafee42593eab87b (patch) | |
tree | 1d6fd9e33d3aadeb187b12d0e0b149d8beb914a3 /src/lib.rs | |
parent | 7d894d9223ff05a2597011a898aa38760c16916f (diff) | |
download | git-suggestion-a22f7a574cbbad22ed637405bafee42593eab87b.tar.bz2 |
Suggestion.apply(): Use `Suggestion.apply_to()`
Replace common code with a call to `Suggestion.apply_to()`.
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 17 |
1 files changed, 1 insertions, 16 deletions
@@ -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<W: Write>(&self, writer: &mut W) ->Result<(), Error> { |