fix clippy lints

master
Lukáš Hozda 4 years ago
parent 8db12bde77
commit 551b860b32

@ -1,3 +1,4 @@
#![allow(clippy::new_without_default)]
extern crate bunt; extern crate bunt;
extern crate dirs; extern crate dirs;
extern crate tempfile; extern crate tempfile;
@ -112,7 +113,7 @@ impl BrowserState {
return false; return false;
} }
let _ = tmpfile.keep(); let _ = tmpfile.keep();
return true; true
} }
pub fn add_link( pub fn add_link(
@ -357,7 +358,7 @@ impl BrowserState {
link = self.history.clone(); link = self.history.clone();
while let Some(l) = link { while let Some(l) = link {
let fresh10 = history_key; let fresh10 = history_key;
history_key = history_key + 1; history_key += 1;
make_key_str(fresh10, &mut a, &mut b, &mut c); make_key_str(fresh10, &mut a, &mut b, &mut c);
bunt::println!("{[green]}{[green]}{[green]} {}:{}/{}", a, b, c, (*l).host, (*l).port, (*l).selector,); bunt::println!("{[green]}{[green]}{[green]} {}:{}/{}", a, b, c, (*l).host, (*l).port, (*l).selector,);
link = (*l).next link = (*l).next
@ -398,7 +399,7 @@ impl BrowserState {
if self.parse_uri(bookmark) { if self.parse_uri(bookmark) {
self.view_directory( self.view_directory(
&self.parsed_host.clone(), &self.parsed_host.clone(),
self.parsed_port.clone(), self.parsed_port,
&self.parsed_selector.clone(), &self.parsed_selector.clone(),
false, false,
); );
@ -561,8 +562,8 @@ impl BrowserState {
let mut uri: String = self.config.start_uri.clone(); let mut uri: String = self.config.start_uri.clone();
/* parse command line */ /* parse command line */
while i < argv.len() { while i < argv.len() {
if argv[i].chars().next() == Some('-') { if argv[i].starts_with('-') {
match argv[i].chars().skip(1).next() { match argv[i].chars().nth(1) {
Some('H') => { Some('H') => {
usage(); usage();
} }
@ -588,7 +589,7 @@ impl BrowserState {
/* main loop */ /* main loop */
self.view_directory( self.view_directory(
&self.parsed_host.clone(), &self.parsed_host.clone(),
self.parsed_port.clone(), self.parsed_port,
&self.parsed_selector.clone(), &self.parsed_selector.clone(),
false, false,
); /* to display the prompt */ ); /* to display the prompt */
@ -628,8 +629,8 @@ impl BrowserState {
self.download_link( self.download_link(
make_key( make_key(
line.chars().next().unwrap(), line.chars().next().unwrap(),
line.chars().skip(1).next().unwrap_or('\0'), line.chars().nth(1).unwrap_or('\0'),
line.chars().skip(2).next().unwrap_or('\0')) line.chars().nth(2).unwrap_or('\0'))
.unwrap_or(0), .unwrap_or(0),
); );
} }
@ -637,15 +638,15 @@ impl BrowserState {
if i == 1 || i == 3 || i == 4 { if i == 1 || i == 3 || i == 4 {
self.view_history(make_key( self.view_history(make_key(
line.chars().next().unwrap(), line.chars().next().unwrap(),
line.chars().skip(1).next().unwrap_or('\0'), line.chars().nth(1).unwrap_or('\0'),
line.chars().skip(2).next().unwrap_or('\0'), line.chars().nth(2).unwrap_or('\0'),
)); ));
}, },
Some('G') => { Some('G') => {
if self.parse_uri(&line[1..]) { if self.parse_uri(&line[1..]) {
self.view_directory( self.view_directory(
&self.parsed_host.clone(), &self.parsed_host.clone(),
self.parsed_port.clone(), self.parsed_port,
&self.parsed_selector.clone(), &self.parsed_selector.clone(),
true, true,
); );
@ -657,16 +658,16 @@ impl BrowserState {
if i == 1 || i == 3 || i == 4 { if i == 1 || i == 3 || i == 4 {
self.view_bookmarks(make_key( self.view_bookmarks(make_key(
line.chars().next().unwrap(), line.chars().next().unwrap(),
line.chars().skip(1).next().unwrap_or('\0'), line.chars().nth(1).unwrap_or('\0'),
line.chars().skip(2).next().unwrap_or('\0'), line.chars().nth(2).unwrap_or('\0'),
)); ));
}, },
x if !x.is_none() => { x if x.is_some() => {
self.follow_link( self.follow_link(
make_key( make_key(
line.chars().next().unwrap(), line.chars().next().unwrap(),
line.chars().skip(1).next().unwrap_or('\0'), line.chars().nth(1).unwrap_or('\0'),
line.chars().skip(2).next().unwrap_or('\0')) line.chars().nth(2).unwrap_or('\0'))
.unwrap_or(0), .unwrap_or(0),
); );
} }

@ -42,16 +42,16 @@ pub fn make_key(c1: char, c2: char, c3: char) -> Option<usize> {
} }
if c3 == '\0' { if c3 == '\0' {
Some( Some(
(c1 as u8 - 'a' as u8) as usize * ('z' as usize - 'a' as usize + 1) (c1 as u8 - b'a') as usize * ('z' as usize - 'a' as usize + 1)
+ (c2 as u8 - 'a' as u8) as usize, + (c2 as u8 - b'a') as usize,
) )
} else { } else {
Some( 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)
* ('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) + ((c2 as u8 - b'a') as usize) * ('z' as usize - 'a' as usize + 1)
+ ((c3 as u8 - 'a' as u8) as usize), + ((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 { pub fn is_valid_directory_entry(kind: char) -> bool {
match kind { matches!(kind, 'i' | '3' | '.' | '0' | '1' | '5' | '7' | '8' | '9' | 'g' | 'I' | 'p' | 'h' | '2' | 'd'| 's')
'i' | '3' | '.' | '0' | '1' | '5' | '7' | '8' | '9' | 'g' | 'I' | 'p' | 'h' | '2' | 'd'
| 's' => true,
_ => false,
}
} }
pub fn view_telnet(host: &str, port: u16) { pub fn view_telnet(host: &str, port: u16) {

Loading…
Cancel
Save