aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2020-07-25 17:39:38 +0200
committerTeddy Wing2020-07-25 17:39:38 +0200
commita22f7a574cbbad22ed637405bafee42593eab87b (patch)
tree1d6fd9e33d3aadeb187b12d0e0b149d8beb914a3
parent7d894d9223ff05a2597011a898aa38760c16916f (diff)
downloadgit-suggestion-a22f7a574cbbad22ed637405bafee42593eab87b.tar.bz2
Suggestion.apply(): Use `Suggestion.apply_to()`
Replace common code with a call to `Suggestion.apply_to()`.
-rw-r--r--src/lib.rs17
1 files changed, 1 insertions, 16 deletions
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<W: Write>(&self, writer: &mut W) ->Result<(), Error> {