diff --git a/src/main.rs b/src/main.rs index 3bb2be80..ee8279b7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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); } } diff --git a/src/report.rs b/src/report.rs index 98a9c9d6..fda8d8b3 100644 --- a/src/report.rs +++ b/src/report.rs @@ -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>>(&self, key: M, report: &mut Report); + fn report<'a, M: Into>>(&self, key: M, report: &mut Report<'a>); } impl Reporter for Result where T: Reporter, { - fn report<'a, M: Into>>(&self, key: M, report: &mut Report) { + fn report<'a, M: Into>>(&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 Reporter for Option where T: Reporter, { - fn report<'a, M: Into>>(&self, key: M, report: &mut Report) { + fn report<'a, M: Into>>(&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>>(&self, key: M, report: &mut Report) { - report.push((key.into().into_owned(), *self)); + fn report<'a, M: Into>>(&self, key: M, report: &mut Report<'a>) { + report.push((key.into(), *self)); } } impl Reporter for () { - fn report<'a, M: Into>>(&self, key: M, report: &mut Report) { - report.push((key.into().into_owned(), true)); + fn report<'a, M: Into>>(&self, key: M, report: &mut Report<'a>) { + report.push((key.into(), true)); } }