From 347c19ddca37f3e37de88871b65b2c12dacaad71 Mon Sep 17 00:00:00 2001 From: Denis Isidoro Date: Sun, 4 Apr 2021 17:42:43 -0300 Subject: [PATCH] Fix warnings (#464) --- src/cmds/core.rs | 12 ++++++------ src/common/terminal_width.rs | 5 ++++- src/display/terminal.rs | 2 +- src/structures/cheat.rs | 3 +-- src/structures/config.rs | 28 ++++++++++++++-------------- 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/cmds/core.rs b/src/cmds/core.rs index 3aac1e5..8f77951 100644 --- a/src/cmds/core.rs +++ b/src/cmds/core.rs @@ -233,9 +233,9 @@ pub fn main(config: Config) -> Result<(), Error> { let mut writer = display::terminal::Writer::new(); let fetcher: Box = match config.source() { - Source::CHEATSH(query) => Box::new(cheatsh::Fetcher::new(query)), - Source::TLDR(query) => Box::new(tldr::Fetcher::new(query)), - Source::FILESYSTEM(path) => Box::new(filesystem::Fetcher::new(path)), + Source::Cheats(query) => Box::new(cheatsh::Fetcher::new(query)), + Source::Tldr(query) => Box::new(tldr::Fetcher::new(query)), + Source::Filesystem(path) => Box::new(filesystem::Fetcher::new(path)), }; let res = fetcher @@ -280,13 +280,13 @@ pub fn main(config: Config) -> Result<(), Error> { ); match config.action() { - Action::PRINT => { + Action::Print => { println!("{}", interpolated_snippet); } - Action::SAVE(filepath) => { + Action::Save(filepath) => { fs::write(filepath, interpolated_snippet).context("Unable to save output")?; } - Action::EXECUTE => match key { + Action::Execute => match key { "ctrl-y" => { clipboard::copy(interpolated_snippet)?; } diff --git a/src/common/terminal_width.rs b/src/common/terminal_width.rs index 91c79ab..bb134cf 100644 --- a/src/common/terminal_width.rs +++ b/src/common/terminal_width.rs @@ -29,7 +29,10 @@ fn width_with_shell_out() -> u16 { let stdout = String::from_utf8(output.stdout).expect("Invalid utf8 output from stty"); let mut data = stdout.split_whitespace(); data.next(); - u16::from_str_radix(data.next().expect("Not enough data"), 10).expect("Invalid base-10 number") + data.next() + .expect("Not enough data") + .parse::() + .expect("Invalid base-10 number") } _ => FALLBACK_WIDTH, } diff --git a/src/display/terminal.rs b/src/display/terminal.rs index 9edd6a7..1eba023 100644 --- a/src/display/terminal.rs +++ b/src/display/terminal.rs @@ -54,7 +54,7 @@ fn get_env_var(name: &str) -> String { if let Ok(v) = env::var(name) { v } else { - panic!(format!("{} not set", name)) + panic!("{} not set", name) } } diff --git a/src/structures/cheat.rs b/src/structures/cheat.rs index 0d4885b..e5b55c8 100644 --- a/src/structures/cheat.rs +++ b/src/structures/cheat.rs @@ -23,8 +23,7 @@ impl VariableMap { if let Some(v) = self.dependencies.get_mut(&k) { v.push(fnv(&tags_dependency)); } else { - let mut v: Vec = Vec::new(); - v.push(fnv(&tags_dependency)); + let v: Vec = vec![fnv(&tags_dependency)]; self.dependencies.insert(k, v); } } diff --git a/src/structures/config.rs b/src/structures/config.rs index 0d3aa32..cc54201 100644 --- a/src/structures/config.rs +++ b/src/structures/config.rs @@ -215,35 +215,35 @@ pub enum AlfredCommand { } pub enum Source { - FILESYSTEM(Option), - TLDR(String), - CHEATSH(String), + Filesystem(Option), + Tldr(String), + Cheats(String), } pub enum Action { - SAVE(String), - PRINT, - EXECUTE, + Save(String), + Print, + Execute, } impl Config { pub fn source(&self) -> Source { if let Some(query) = self.tldr.clone() { - Source::TLDR(query) + Source::Tldr(query) } else if let Some(query) = self.cheatsh.clone() { - Source::CHEATSH(query) + Source::Cheats(query) } else { - Source::FILESYSTEM(self.path.clone()) + Source::Filesystem(self.path.clone()) } } pub fn action(&self) -> Action { if let Some(filepath) = self.save.clone() { - Action::SAVE(filepath) + Action::Save(filepath) } else if self.print { - Action::PRINT + Action::Print } else { - Action::EXECUTE + Action::Execute } } @@ -254,8 +254,8 @@ impl Config { } if self.best_match { match self.source() { - Source::TLDR(q) => Some(q), - Source::CHEATSH(q) => Some(q), + Source::Tldr(q) => Some(q), + Source::Cheats(q) => Some(q), _ => Some(String::from("")), } } else {