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