Replace Cow by String

This commit is contained in:
Pit Kleyersburg 2018-05-09 22:31:38 +02:00 committed by David Peter
parent 61109ece15
commit 747d074be1

View File

@ -1,6 +1,5 @@
use ansi_term::Style; use ansi_term::Style;
use errors::*; use errors::*;
use std::borrow::Cow;
use std::io::Write; use std::io::Write;
use syntect::highlighting; use syntect::highlighting;
use terminal::as_terminal_escaped; use terminal::as_terminal_escaped;
@ -80,13 +79,11 @@ impl<'a> Printer<'a> {
self.print_line_number(line_number), self.print_line_number(line_number),
self.print_git_marker(line_number), self.print_git_marker(line_number),
self.print_line_border(), self.print_line_border(),
Some( Some(as_terminal_escaped(
as_terminal_escaped( &regions,
&regions, self.options.true_color,
self.options.true_color, self.options.colored_output,
self.options.colored_output, )),
).into(),
),
]; ];
let grid_requested = self.options.output_components.grid(); let grid_requested = self.options.output_components.grid();
@ -96,7 +93,7 @@ impl<'a> Printer<'a> {
decorations decorations
.into_iter() .into_iter()
.filter_map(|dec| if grid_requested { .filter_map(|dec| if grid_requested {
Some(dec.unwrap_or(" ".into())) Some(dec.unwrap_or(" ".to_owned()))
} else { } else {
dec dec
}) })
@ -107,23 +104,22 @@ impl<'a> Printer<'a> {
Ok(()) Ok(())
} }
fn print_line_number<'s>(&self, line_number: usize) -> Option<Cow<'s, str>> { fn print_line_number<'s>(&self, line_number: usize) -> Option<String> {
if self.options.output_components.numbers() { if self.options.output_components.numbers() {
Some( Some(
self.colors self.colors
.line_number .line_number
.paint(format!("{:4}", line_number)) .paint(format!("{:4}", line_number))
.to_string() .to_string(),
.into(),
) )
} else if self.options.output_components.grid() { } else if self.options.output_components.grid() {
Some(" ".into()) Some(" ".to_owned())
} else { } else {
None None
} }
} }
fn print_git_marker<'s>(&self, line_number: usize) -> Option<Cow<'s, str>> { fn print_git_marker<'s>(&self, line_number: usize) -> Option<String> {
if self.options.output_components.changes() { if self.options.output_components.changes() {
Some( Some(
if let Some(ref changes) = self.line_changes { if let Some(ref changes) = self.line_changes {
@ -136,19 +132,18 @@ impl<'a> Printer<'a> {
} }
} else { } else {
Style::default().paint(" ") Style::default().paint(" ")
}.to_string() }.to_string(),
.into(),
) )
} else if self.options.output_components.grid() { } else if self.options.output_components.grid() {
Some(" ".into()) Some(" ".to_owned())
} else { } else {
None None
} }
} }
fn print_line_border<'s>(&self) -> Option<Cow<'s, str>> { fn print_line_border<'s>(&self) -> Option<String> {
if self.options.output_components.grid() { if self.options.output_components.grid() {
Some(self.colors.grid.paint("").to_string().into()) Some(self.colors.grid.paint("").to_string())
} else { } else {
None None
} }