From 551b860b32af6ed9463fde2dafe23efa0090ea5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hozda?= Date: Tue, 18 Aug 2020 23:54:35 +0200 Subject: [PATCH] fix clippy lints --- src/main.rs | 33 +++++++++++++++++---------------- src/util.rs | 16 ++++++---------- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/main.rs b/src/main.rs index a751fa5..beed083 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +#![allow(clippy::new_without_default)] extern crate bunt; extern crate dirs; extern crate tempfile; @@ -112,7 +113,7 @@ impl BrowserState { return false; } let _ = tmpfile.keep(); - return true; + true } pub fn add_link( @@ -357,7 +358,7 @@ impl BrowserState { link = self.history.clone(); while let Some(l) = link { let fresh10 = history_key; - history_key = history_key + 1; + history_key += 1; make_key_str(fresh10, &mut a, &mut b, &mut c); bunt::println!("{[green]}{[green]}{[green]} {}:{}/{}", a, b, c, (*l).host, (*l).port, (*l).selector,); link = (*l).next @@ -398,7 +399,7 @@ impl BrowserState { if self.parse_uri(bookmark) { self.view_directory( &self.parsed_host.clone(), - self.parsed_port.clone(), + self.parsed_port, &self.parsed_selector.clone(), false, ); @@ -561,8 +562,8 @@ impl BrowserState { let mut uri: String = self.config.start_uri.clone(); /* parse command line */ while i < argv.len() { - if argv[i].chars().next() == Some('-') { - match argv[i].chars().skip(1).next() { + if argv[i].starts_with('-') { + match argv[i].chars().nth(1) { Some('H') => { usage(); } @@ -588,7 +589,7 @@ impl BrowserState { /* main loop */ self.view_directory( &self.parsed_host.clone(), - self.parsed_port.clone(), + self.parsed_port, &self.parsed_selector.clone(), false, ); /* to display the prompt */ @@ -628,8 +629,8 @@ impl BrowserState { self.download_link( make_key( line.chars().next().unwrap(), - line.chars().skip(1).next().unwrap_or('\0'), - line.chars().skip(2).next().unwrap_or('\0')) + line.chars().nth(1).unwrap_or('\0'), + line.chars().nth(2).unwrap_or('\0')) .unwrap_or(0), ); } @@ -637,15 +638,15 @@ impl BrowserState { if i == 1 || i == 3 || i == 4 { self.view_history(make_key( line.chars().next().unwrap(), - line.chars().skip(1).next().unwrap_or('\0'), - line.chars().skip(2).next().unwrap_or('\0'), + line.chars().nth(1).unwrap_or('\0'), + line.chars().nth(2).unwrap_or('\0'), )); }, Some('G') => { if self.parse_uri(&line[1..]) { self.view_directory( &self.parsed_host.clone(), - self.parsed_port.clone(), + self.parsed_port, &self.parsed_selector.clone(), true, ); @@ -657,16 +658,16 @@ impl BrowserState { if i == 1 || i == 3 || i == 4 { self.view_bookmarks(make_key( line.chars().next().unwrap(), - line.chars().skip(1).next().unwrap_or('\0'), - line.chars().skip(2).next().unwrap_or('\0'), + line.chars().nth(1).unwrap_or('\0'), + line.chars().nth(2).unwrap_or('\0'), )); }, - x if !x.is_none() => { + x if x.is_some() => { self.follow_link( make_key( line.chars().next().unwrap(), - line.chars().skip(1).next().unwrap_or('\0'), - line.chars().skip(2).next().unwrap_or('\0')) + line.chars().nth(1).unwrap_or('\0'), + line.chars().nth(2).unwrap_or('\0')) .unwrap_or(0), ); } diff --git a/src/util.rs b/src/util.rs index 0406c7b..d9d1b33 100644 --- a/src/util.rs +++ b/src/util.rs @@ -42,16 +42,16 @@ pub fn make_key(c1: char, c2: char, c3: char) -> Option { } if c3 == '\0' { Some( - (c1 as u8 - 'a' as u8) as usize * ('z' as usize - 'a' as usize + 1) - + (c2 as u8 - 'a' as u8) as usize, + (c1 as u8 - b'a') as usize * ('z' as usize - 'a' as usize + 1) + + (c2 as u8 - b'a') as usize, ) } else { Some( - ((c1 as u8 - 'a' as u8) as usize + 1) + ((c1 as u8 - b'a') as usize + 1) * ('z' as usize - 'a' as usize + 1) * ('z' as usize - 'a' as usize + 1) - + ((c2 as u8 - 'a' as u8) as usize) * ('z' as usize - 'a' as usize + 1) - + ((c3 as u8 - 'a' as u8) as usize), + + ((c2 as u8 - b'a') as usize) * ('z' as usize - 'a' as usize + 1) + + ((c3 as u8 - b'a') as usize), ) } } @@ -85,11 +85,7 @@ pub fn make_key_str( } pub fn is_valid_directory_entry(kind: char) -> bool { - match kind { - 'i' | '3' | '.' | '0' | '1' | '5' | '7' | '8' | '9' | 'g' | 'I' | 'p' | 'h' | '2' | 'd' - | 's' => true, - _ => false, - } + matches!(kind, 'i' | '3' | '.' | '0' | '1' | '5' | '7' | '8' | '9' | 'g' | 'I' | 'p' | 'h' | '2' | 'd'| 's') } pub fn view_telnet(host: &str, port: u16) {