From 124b7fdc0571c53926e99e0c8b256e1ec747c6b2 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 21 Feb 2018 10:29:27 -0500 Subject: clippy --- src/colors.rs | 4 ++-- src/prompt.rs | 28 ++++++++++++++++------------ src/system_info.rs | 4 ++-- src/vcs/git.rs | 4 ++-- src/vcs/mod.rs | 1 + 5 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/colors.rs b/src/colors.rs index 197881c..199f4f9 100644 --- a/src/colors.rs +++ b/src/colors.rs @@ -59,8 +59,8 @@ impl Colors { fn read_colors_from_env(color_map: &mut ColorMap) { if let Ok(val) = std::env::var("FANCY_PROMPT_COLORS") { - for mapping in val.split(",") { - let parts: Vec<_> = mapping.split("=").collect(); + for mapping in val.split(',') { + let parts: Vec<_> = mapping.split('=').collect(); let (name, color) = (parts[0], parts[1]); color_map.insert( String::from(name), diff --git a/src/prompt.rs b/src/prompt.rs index c05ec8b..4a574a4 100644 --- a/src/prompt.rs +++ b/src/prompt.rs @@ -39,8 +39,12 @@ impl Prompt { } pub fn display(&self) { - let user = self.data.user.clone().unwrap_or(String::from("???")); - let host = self.data.hostname.clone().unwrap_or(String::from("???")); + let user = self.data.user + .clone() + .unwrap_or_else(|| String::from("???")); + let host = self.data.hostname + .clone() + .unwrap_or_else(|| String::from("???")); let max_vcs_len = 20; // "g*+?:mybr...nch:+1-1" let vcs = self.format_vcs(); @@ -120,9 +124,9 @@ impl Prompt { ) { self.colors.print_host(&self.data.hostname, "("); self.colors.print(path_color, path); - if let &Some(ref vcs) = vcs { + if let Some(ref vcs) = *vcs { self.colors.print_host(&self.data.hostname, "|"); - self.colors.print(vcs_color, &vcs); + self.colors.print(vcs_color, vcs); } self.colors.print_host(&self.data.hostname, ")"); } @@ -158,9 +162,9 @@ impl Prompt { } fn display_identity(&self, user: &str, host: &str) { - self.colors.print_user(&self.data.user, &user); + self.colors.print_user(&self.data.user, user); self.colors.print("default", "@"); - self.colors.print_host(&self.data.hostname, &host); + self.colors.print_host(&self.data.hostname, host); } fn display_time(&self) { @@ -216,7 +220,7 @@ impl Prompt { else { branch } - }).unwrap_or(String::from("???")); + }).unwrap_or_else(|| String::from("???")); if branch != "" { write!(vcs, ":").unwrap(); } @@ -259,7 +263,7 @@ impl Prompt { else { String::from("default") } - }).unwrap_or(String::from("vcs_error")) + }).unwrap_or_else(|| String::from("vcs_error")) } } @@ -313,7 +317,7 @@ fn path_color(path: &Option) -> String String::from("path_not_writable") } }).ok() - }).unwrap_or(String::from("path_not_exist")) + }).unwrap_or_else(|| String::from("path_not_exist")) } fn compress_path( @@ -324,10 +328,10 @@ fn compress_path( where T: AsRef, U: AsRef { - if let &Some(ref path) = path { + if let Some(ref path) = *path { let mut path_str = path.as_ref().to_string_lossy().into_owned(); - if let &Some(ref home) = home { + if let Some(ref home) = *home { let home_str = home.as_ref().to_string_lossy().into_owned(); let home_re = regex::Regex::new( &(String::from(r"^") + ®ex::escape(&home_str)) @@ -384,7 +388,7 @@ fn compress_vcs(vcs: &str, len: usize) -> String { ).unwrap(); branch_re.replace(vcs, "$1...$2").into_owned() }) - .unwrap_or(vcs.to_string()) + .unwrap_or_else(|| vcs.to_string()) } else { vcs.to_string() diff --git a/src/system_info.rs b/src/system_info.rs index cec17fd..a4c4122 100644 --- a/src/system_info.rs +++ b/src/system_info.rs @@ -22,13 +22,13 @@ pub fn terminal_cols() -> Option { pub fn pwd() -> Option { std::env::var("PWD") - .map(|pwd| std::path::PathBuf::from(pwd)) + .map(std::path::PathBuf::from) .ok() } pub fn home() -> Option { std::env::var("HOME") - .map(|dir| std::path::PathBuf::from(dir)) + .map(std::path::PathBuf::from) .ok() } diff --git a/src/vcs/git.rs b/src/vcs/git.rs index 749d498..2eced81 100644 --- a/src/vcs/git.rs +++ b/src/vcs/git.rs @@ -15,7 +15,7 @@ pub struct GitInfo { } impl GitInfo { - pub fn new(git: git2::Repository) -> GitInfo { + pub fn new(git: &git2::Repository) -> GitInfo { let mut modified_statuses = git2::Status::empty(); modified_statuses.insert(git2::STATUS_WT_DELETED); modified_statuses.insert(git2::STATUS_WT_MODIFIED); @@ -168,7 +168,7 @@ pub fn detect() -> Option> { }); if let Some(git) = git { - Some(Box::new(GitInfo::new(git))) + Some(Box::new(GitInfo::new(&git))) } else { None diff --git a/src/vcs/mod.rs b/src/vcs/mod.rs index 50ef720..f68e4ef 100644 --- a/src/vcs/mod.rs +++ b/src/vcs/mod.rs @@ -1,5 +1,6 @@ mod git; +#[derive(Debug,Copy,Clone)] pub enum VcsType { Git, } -- cgit v1.2.3