Prevent unnecessary copy
This commit is contained in:
@@ -95,8 +95,8 @@ fn run() -> Result<(), Error> {
|
||||
let git = Git::new();
|
||||
let mut git_repos = Repositories::new(&git);
|
||||
let terminal = Terminal::new();
|
||||
let mut reports = Report::new();
|
||||
let config = Config::read()?;
|
||||
let mut reports = Report::new();
|
||||
|
||||
let sudo = if cfg!(target_os = "linux") {
|
||||
utils::which("sudo")
|
||||
@@ -232,7 +232,7 @@ fn run() -> Result<(), Error> {
|
||||
if let Some(commands) = config.commands() {
|
||||
for (name, command) in commands {
|
||||
terminal.print_separator(name);
|
||||
run_custom_command(&command).report(name.as_ref(), &mut reports);
|
||||
run_custom_command(&command).report(name.as_str(), &mut reports);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
pub type Report = Vec<(String, bool)>;
|
||||
type CowString<'a> = Cow<'a, str>;
|
||||
pub type Report<'a> = Vec<(CowString<'a>, bool)>;
|
||||
|
||||
pub trait Reporter {
|
||||
fn report<'a, M: Into<Cow<'a, str>>>(&self, key: M, report: &mut Report);
|
||||
fn report<'a, M: Into<CowString<'a>>>(&self, key: M, report: &mut Report<'a>);
|
||||
}
|
||||
|
||||
impl<T, E> Reporter for Result<T, E>
|
||||
where
|
||||
T: Reporter,
|
||||
{
|
||||
fn report<'a, M: Into<Cow<'a, str>>>(&self, key: M, report: &mut Report) {
|
||||
fn report<'a, M: Into<CowString<'a>>>(&self, key: M, report: &mut Report<'a>) {
|
||||
match self {
|
||||
Err(_) => {
|
||||
report.push((key.into().into_owned(), false));
|
||||
report.push((key.into(), false));
|
||||
}
|
||||
Ok(item) => {
|
||||
item.report(key, report);
|
||||
@@ -26,7 +27,7 @@ impl<T> Reporter for Option<T>
|
||||
where
|
||||
T: Reporter,
|
||||
{
|
||||
fn report<'a, M: Into<Cow<'a, str>>>(&self, key: M, report: &mut Report) {
|
||||
fn report<'a, M: Into<CowString<'a>>>(&self, key: M, report: &mut Report<'a>) {
|
||||
if let Some(item) = self {
|
||||
item.report(key, report);
|
||||
}
|
||||
@@ -34,13 +35,13 @@ where
|
||||
}
|
||||
|
||||
impl Reporter for bool {
|
||||
fn report<'a, M: Into<Cow<'a, str>>>(&self, key: M, report: &mut Report) {
|
||||
report.push((key.into().into_owned(), *self));
|
||||
fn report<'a, M: Into<CowString<'a>>>(&self, key: M, report: &mut Report<'a>) {
|
||||
report.push((key.into(), *self));
|
||||
}
|
||||
}
|
||||
|
||||
impl Reporter for () {
|
||||
fn report<'a, M: Into<Cow<'a, str>>>(&self, key: M, report: &mut Report) {
|
||||
report.push((key.into().into_owned(), true));
|
||||
fn report<'a, M: Into<CowString<'a>>>(&self, key: M, report: &mut Report<'a>) {
|
||||
report.push((key.into(), true));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user