summaryrefslogtreecommitdiff
path: root/cli/diff.rs
diff options
context:
space:
mode:
authorValentin Anger <syrupthinker@gryphno.de>2020-06-29 14:17:37 +0200
committerGitHub <noreply@github.com>2020-06-29 14:17:37 +0200
commitdb36857288609858ada259444509a31637980ce3 (patch)
tree9fc83f32408941bdf75d803b4b0dbffe297c10f2 /cli/diff.rs
parent0374eadcf7ecb054dae1b1587843a2006fdf4c2d (diff)
refactor: util functions take slices instead of heap values (#6547)
Diffstat (limited to 'cli/diff.rs')
-rw-r--r--cli/diff.rs24
1 files changed, 12 insertions, 12 deletions
diff --git a/cli/diff.rs b/cli/diff.rs
index e6d7fa4bb..121e319f4 100644
--- a/cli/diff.rs
+++ b/cli/diff.rs
@@ -5,26 +5,26 @@ use std::fmt;
use std::fmt::Write;
fn fmt_add() -> String {
- format!("{}", colors::green_bold("+".to_string()))
+ format!("{}", colors::green_bold("+"))
}
-fn fmt_add_text(x: String) -> String {
+fn fmt_add_text(x: &str) -> String {
format!("{}", colors::green(x))
}
-fn fmt_add_text_highlight(x: String) -> String {
+fn fmt_add_text_highlight(x: &str) -> String {
format!("{}", colors::white_on_green(x))
}
fn fmt_rem() -> String {
- format!("{}", colors::red_bold("-".to_string()))
+ format!("{}", colors::red_bold("-"))
}
-fn fmt_rem_text(x: String) -> String {
+fn fmt_rem_text(x: &str) -> String {
format!("{}", colors::red(x))
}
-fn fmt_rem_text_highlight(x: String) -> String {
+fn fmt_rem_text_highlight(x: &str) -> String {
format!("{}", colors::white_on_red(x))
}
@@ -42,7 +42,7 @@ fn write_line_diff(
diff,
"{:0width$}{} ",
*orig_line + i,
- colors::gray("|".to_string()),
+ colors::gray("|"),
width = line_number_width
)?;
write!(diff, "{}", fmt_rem())?;
@@ -56,7 +56,7 @@ fn write_line_diff(
diff,
"{:0width$}{} ",
*edit_line + i,
- colors::gray("|".to_string()),
+ colors::gray("|"),
width = line_number_width
)?;
write!(diff, "{}", fmt_add())?;
@@ -107,7 +107,7 @@ pub fn diff(orig_text: &str, edit_text: &str) -> Result<String, fmt::Error> {
if i > 0 {
orig.push_str("\n");
}
- orig.push_str(&fmt_rem_text_highlight(s.to_string()));
+ orig.push_str(&fmt_rem_text_highlight(s));
}
changes = true
}
@@ -117,7 +117,7 @@ pub fn diff(orig_text: &str, edit_text: &str) -> Result<String, fmt::Error> {
if i > 0 {
edit.push_str("\n");
}
- edit.push_str(&fmt_add_text_highlight(s.to_string()));
+ edit.push_str(&fmt_add_text_highlight(s));
}
changes = true
}
@@ -142,8 +142,8 @@ pub fn diff(orig_text: &str, edit_text: &str) -> Result<String, fmt::Error> {
edit_line += 1;
}
}
- orig.push_str(&fmt_rem_text(s.to_string()));
- edit.push_str(&fmt_add_text(s.to_string()));
+ orig.push_str(&fmt_rem_text(s));
+ edit.push_str(&fmt_add_text(s));
}
}
}