Fix most clippy warnings, bump version

This commit is contained in:
Stephen Seo 2022-01-13 10:07:01 +09:00
parent 483075d62d
commit a48f801a02
7 changed files with 72 additions and 71 deletions

2
Cargo.lock generated
View file

@ -1427,7 +1427,7 @@ dependencies = [
[[package]] [[package]]
name = "mpd_info_screen" name = "mpd_info_screen"
version = "0.2.13" version = "0.2.14"
dependencies = [ dependencies = [
"ggez", "ggez",
"image", "image",

View file

@ -1,6 +1,6 @@
[package] [package]
name = "mpd_info_screen" name = "mpd_info_screen"
version = "0.2.13" version = "0.2.14"
edition = "2018" edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View file

@ -9,7 +9,7 @@ counter, and the filename currently being played
# Usage # Usage
mpd_info_screen 0.2.13 mpd_info_screen 0.2.14
USAGE: USAGE:
mpd_info_screen [FLAGS] [OPTIONS] <host> [port] mpd_info_screen [FLAGS] [OPTIONS] <host> [port]
@ -24,13 +24,14 @@ counter, and the filename currently being played
-V, --version Prints version information -V, --version Prints version information
OPTIONS: OPTIONS:
-l, --log-level <log-level> [default: ERROR] [possible values: ERROR, WARNING, DEBUG, VERBOSE] -l, --log-level <log-level> [default: Error] [possible values: Error, Warning, Debug, Verbose]
-p <password> -p <password>
ARGS: ARGS:
<host> <host>
<port> [default: 6600] <port> [default: 6600]
Note that presing the Escape key when the window is focused closes the program. Note that presing the Escape key when the window is focused closes the program.
Also note that pressing the H key while displaying text will hide the text. Also note that pressing the H key while displaying text will hide the text.

View file

@ -3,19 +3,19 @@ use structopt::clap::arg_enum;
#[derive(Copy, Clone, Debug, PartialEq)] #[derive(Copy, Clone, Debug, PartialEq)]
pub enum LogState { pub enum LogState {
ERROR, Error,
WARNING, Warning,
DEBUG, Debug,
VERBOSE, Verbose,
} }
arg_enum! { arg_enum! {
#[derive(Copy, Clone, Debug, PartialEq)] #[derive(Copy, Clone, Debug, PartialEq)]
pub enum LogLevel { pub enum LogLevel {
ERROR, Error,
WARNING, Warning,
DEBUG, Debug,
VERBOSE, Verbose,
} }
} }
@ -23,18 +23,18 @@ pub fn log<T>(msg: T, state: LogState, level: LogLevel)
where where
T: Display, T: Display,
{ {
if state == LogState::ERROR { if state == LogState::Error {
log_error(msg); log_error(msg);
} else if state == LogState::WARNING { } else if state == LogState::Warning {
if level != LogLevel::ERROR { if level != LogLevel::Error {
log_warning(msg); log_warning(msg);
} }
} else if state == LogState::DEBUG { } else if state == LogState::Debug {
if level == LogLevel::DEBUG || level == LogLevel::VERBOSE { if level == LogLevel::Debug || level == LogLevel::Verbose {
log_debug(msg); log_debug(msg);
} }
} else if state == LogState::VERBOSE { } else if state == LogState::Verbose {
if level == LogLevel::VERBOSE { if level == LogLevel::Verbose {
log_verbose(msg); log_verbose(msg);
} }
} else { } else {
@ -46,26 +46,26 @@ pub fn log_error<T>(msg: T)
where where
T: Display, T: Display,
{ {
println!("ERROR: {}", msg); println!("Error: {}", msg);
} }
pub fn log_warning<T>(msg: T) pub fn log_warning<T>(msg: T)
where where
T: Display, T: Display,
{ {
println!("WARNING: {}", msg); println!("Warning: {}", msg);
} }
pub fn log_debug<T>(msg: T) pub fn log_debug<T>(msg: T)
where where
T: Display, T: Display,
{ {
println!("DEBUG: {}", msg); println!("Debug: {}", msg);
} }
pub fn log_verbose<T>(msg: T) pub fn log_verbose<T>(msg: T)
where where
T: Display, T: Display,
{ {
println!("VERBOSE: {}", msg); println!("Verbose: {}", msg);
} }

View file

@ -132,14 +132,14 @@ impl MPDDisplay {
} }
log( log(
"Successfully initialized MPDHandler", "Successfully initialized MPDHandler",
debug_log::LogState::DEBUG, debug_log::LogState::Debug,
self.opts.log_level, self.opts.log_level,
); );
} else { } else {
self.is_valid = false; self.is_valid = false;
log( log(
"Failed to initialize MPDHandler", "Failed to initialize MPDHandler",
debug_log::LogState::DEBUG, debug_log::LogState::Debug,
self.opts.log_level, self.opts.log_level,
); );
} }
@ -212,7 +212,7 @@ impl MPDDisplay {
"Got image_format type {}", "Got image_format type {}",
read_guard_opt.as_ref().unwrap().get_art_type() read_guard_opt.as_ref().unwrap().get_art_type()
), ),
debug_log::LogState::DEBUG, debug_log::LogState::Debug,
self.opts.log_level, self.opts.log_level,
); );
@ -242,7 +242,7 @@ impl MPDDisplay {
.unwrap() .unwrap()
.force_try_other_album_art() .force_try_other_album_art()
.map_err(|_| String::from("Failed to force try other album art fetching method"))?; .map_err(|_| String::from("Failed to force try other album art fetching method"))?;
return Err("Got unknown format album art image".into()); Err("Got unknown format album art image".into())
}; };
if is_unknown_format && !self.tried_album_art_in_dir { if is_unknown_format && !self.tried_album_art_in_dir {
@ -256,7 +256,7 @@ impl MPDDisplay {
let img_result = ImageReader::with_format(Cursor::new(&image_ref), image_format) let img_result = ImageReader::with_format(Cursor::new(&image_ref), image_format)
.decode() .decode()
.map_err(|e| format!("ERROR: Failed to decode album art image: {}", e)); .map_err(|e| format!("Error: Failed to decode album art image: {}", e));
if img_result.is_err() && !self.tried_album_art_in_dir { if img_result.is_err() && !self.tried_album_art_in_dir {
return try_second_art_fetch_method( return try_second_art_fetch_method(
&mut self.tried_album_art_in_dir, &mut self.tried_album_art_in_dir,
@ -273,7 +273,7 @@ impl MPDDisplay {
rgba8.height() as u16, rgba8.height() as u16,
rgba8.as_raw(), rgba8.as_raw(),
) )
.map_err(|e| format!("ERROR: Failed to load album art image in ggez Image: {}", e))?; .map_err(|e| format!("Error: Failed to load album art image in ggez Image: {}", e))?;
self.album_art = Some(ggez_img); self.album_art = Some(ggez_img);
@ -332,12 +332,12 @@ impl MPDDisplay {
text_height_limit text_height_limit
}) })
{ {
current_x = current_x * DECREASE_AMT; current_x *= DECREASE_AMT;
current_y = current_y * DECREASE_AMT; current_y *= DECREASE_AMT;
continue; continue;
} else if screen_coords.w * MIN_WIDTH_RATIO > width { } else if screen_coords.w * MIN_WIDTH_RATIO > width {
current_x = current_x * INCREASE_AMT; current_x *= INCREASE_AMT;
current_y = current_y * INCREASE_AMT; current_y *= INCREASE_AMT;
continue; continue;
} else { } else {
break; break;
@ -385,7 +385,7 @@ impl MPDDisplay {
} else { } else {
log( log(
"filename text is empty", "filename text is empty",
debug_log::LogState::WARNING, debug_log::LogState::Warning,
self.opts.log_level, self.opts.log_level,
); );
} }
@ -404,7 +404,7 @@ impl MPDDisplay {
} else { } else {
log( log(
"artist text is empty", "artist text is empty",
debug_log::LogState::WARNING, debug_log::LogState::Warning,
self.opts.log_level, self.opts.log_level,
); );
} }
@ -423,7 +423,7 @@ impl MPDDisplay {
} else { } else {
log( log(
"title text is empty", "title text is empty",
debug_log::LogState::WARNING, debug_log::LogState::Warning,
self.opts.log_level, self.opts.log_level,
); );
} }
@ -566,7 +566,7 @@ impl EventHandler for MPDDisplay {
{ {
log( log(
"dirty_flag cleared, acquiring shared data...", "dirty_flag cleared, acquiring shared data...",
debug_log::LogState::DEBUG, debug_log::LogState::Debug,
self.opts.log_level, self.opts.log_level,
); );
self.shared = self self.shared = self
@ -613,14 +613,14 @@ impl EventHandler for MPDDisplay {
} else { } else {
log( log(
"Failed to acquire read lock for getting shared data", "Failed to acquire read lock for getting shared data",
debug_log::LogState::DEBUG, debug_log::LogState::Debug,
self.opts.log_level, self.opts.log_level,
); );
} }
if self.album_art.is_none() { if self.album_art.is_none() {
let result = self.get_image_from_data(ctx); let result = self.get_image_from_data(ctx);
if let Err(e) = result { if let Err(e) = result {
log(e, debug_log::LogState::WARNING, self.opts.log_level); log(e, debug_log::LogState::Warning, self.opts.log_level);
self.album_art = None; self.album_art = None;
self.album_art_draw_transform = None; self.album_art_draw_transform = None;
} else { } else {

View file

@ -39,7 +39,7 @@ pub struct Opt {
short = "l", short = "l",
long = "log-level", long = "log-level",
possible_values = &debug_log::LogLevel::variants(), possible_values = &debug_log::LogLevel::variants(),
default_value = "ERROR", default_value = "Error",
case_insensitive = true, case_insensitive = true,
)] )]
log_level: debug_log::LogLevel, log_level: debug_log::LogLevel,
@ -120,7 +120,7 @@ fn main() -> Result<(), String> {
} }
x => log( x => log(
format!("Other window event fired: {:?}", x), format!("Other window event fired: {:?}", x),
debug_log::LogState::VERBOSE, debug_log::LogState::Verbose,
opt.log_level, opt.log_level,
), ),
}, },
@ -129,13 +129,13 @@ fn main() -> Result<(), String> {
let mut game_result: Result<(), GameError> = display.update(ctx); let mut game_result: Result<(), GameError> = display.update(ctx);
if game_result.is_err() { if game_result.is_err() {
println!("ERROR update: {}", game_result.unwrap_err()); println!("Error update: {}", game_result.unwrap_err());
*control_flow = ControlFlow::Exit; *control_flow = ControlFlow::Exit;
return; return;
} }
game_result = display.draw(ctx); game_result = display.draw(ctx);
if game_result.is_err() { if game_result.is_err() {
println!("ERROR draw: {}", game_result.unwrap_err()); println!("Error draw: {}", game_result.unwrap_err());
*control_flow = ControlFlow::Exit; *control_flow = ControlFlow::Exit;
return; return;
} }
@ -148,7 +148,7 @@ fn main() -> Result<(), String> {
} }
x => log( x => log(
format!("Device event fired: {:?}", x), format!("Device event fired: {:?}", x),
debug_log::LogState::VERBOSE, debug_log::LogState::Verbose,
opt.log_level, opt.log_level,
), ),
} }

View file

@ -195,7 +195,7 @@ fn read_line(
buf_to_read = buf_to_read.split_off(2); buf_to_read = buf_to_read.split_off(2);
result = String::from("OK"); result = String::from("OK");
buf.append(&mut buf_to_read); buf.append(&mut buf_to_read);
//println!("WARNING: OK was reached"); // DEBUG //println!("Warning: OK was reached"); // DEBUG
return Ok(result); return Ok(result);
} }
} }
@ -207,7 +207,7 @@ fn read_line(
result.push(c); result.push(c);
skip_count = s - 1; skip_count = s - 1;
} else if let Err((msg, count)) = next_char_result { } else if let Err((msg, count)) = next_char_result {
//println!("ERROR: {}", msg); // DEBUG //println!("Error: {}", msg); // DEBUG
for i in 0..count { for i in 0..count {
saved.push(buf_to_read[idx + i as usize]); saved.push(buf_to_read[idx + i as usize]);
} }
@ -392,7 +392,7 @@ impl MPDHandler {
// main thread failed to store handle to this thread // main thread failed to store handle to this thread
log( log(
"MPDHandle thread stopping due to failed handle storage", "MPDHandle thread stopping due to failed handle storage",
LogState::ERROR, LogState::Error,
write_handle.log_level, write_handle.log_level,
); );
break 'main; break 'main;
@ -403,13 +403,13 @@ impl MPDHandler {
if let Err(err_string) = self.handler_read_block(&mut buf, &mut saved, &mut saved_str) { if let Err(err_string) = self.handler_read_block(&mut buf, &mut saved, &mut saved_str) {
log( log(
format!("read_block error: {}", err_string), format!("read_block error: {}", err_string),
LogState::WARNING, LogState::Warning,
log_level, log_level,
); );
} else if let Err(err_string) = self.handler_write_block() { } else if let Err(err_string) = self.handler_write_block() {
log( log(
format!("write_block error: {}", err_string), format!("write_block error: {}", err_string),
LogState::WARNING, LogState::Warning,
log_level, log_level,
); );
} }
@ -425,7 +425,7 @@ impl MPDHandler {
log( log(
"MPDHandler thread entering exit loop", "MPDHandler thread entering exit loop",
LogState::DEBUG, LogState::Debug,
log_level, log_level,
); );
'exit: loop { 'exit: loop {
@ -479,7 +479,7 @@ impl MPDHandler {
write_handle.art_data.len(), write_handle.art_data.len(),
write_handle.art_data_size write_handle.art_data_size
), ),
LogState::DEBUG, LogState::Debug,
write_handle.log_level, write_handle.log_level,
); );
if write_handle.art_data.len() == write_handle.art_data_size { if write_handle.art_data.len() == write_handle.art_data_size {
@ -494,7 +494,7 @@ impl MPDHandler {
write_handle.art_data.len(), write_handle.art_data.len(),
write_handle.art_data_size write_handle.art_data_size
), ),
LogState::DEBUG, LogState::Debug,
write_handle.log_level, write_handle.log_level,
); );
if write_handle.art_data.len() == write_handle.art_data_size { if write_handle.art_data.len() == write_handle.art_data_size {
@ -512,7 +512,7 @@ impl MPDHandler {
write_handle.is_init = false; write_handle.is_init = false;
log( log(
"Got initial \"OK\" from MPD", "Got initial \"OK\" from MPD",
LogState::DEBUG, LogState::Debug,
write_handle.log_level, write_handle.log_level,
); );
write_handle.poll_state = PollState::None; write_handle.poll_state = PollState::None;
@ -525,7 +525,7 @@ impl MPDHandler {
if line.starts_with("OK") { if line.starts_with("OK") {
log( log(
format!("Got OK when poll state is {:?}", write_handle.poll_state), format!("Got OK when poll state is {:?}", write_handle.poll_state),
LogState::DEBUG, LogState::Debug,
write_handle.log_level, write_handle.log_level,
); );
match write_handle.poll_state { match write_handle.poll_state {
@ -536,7 +536,7 @@ impl MPDHandler {
write_handle.dirty_flag.store(true, Ordering::Relaxed); write_handle.dirty_flag.store(true, Ordering::Relaxed);
log( log(
"No embedded album art", "No embedded album art",
LogState::WARNING, LogState::Warning,
write_handle.log_level, write_handle.log_level,
); );
} }
@ -547,7 +547,7 @@ impl MPDHandler {
write_handle.dirty_flag.store(true, Ordering::Relaxed); write_handle.dirty_flag.store(true, Ordering::Relaxed);
log( log(
"No album art in dir", "No album art in dir",
LogState::WARNING, LogState::Warning,
write_handle.log_level, write_handle.log_level,
); );
} }
@ -557,7 +557,7 @@ impl MPDHandler {
write_handle.poll_state = PollState::None; write_handle.poll_state = PollState::None;
break 'handle_buf; break 'handle_buf;
} else if line.starts_with("ACK") { } else if line.starts_with("ACK") {
log(line, LogState::WARNING, write_handle.log_level); log(line, LogState::Warning, write_handle.log_level);
match write_handle.poll_state { match write_handle.poll_state {
PollState::Password => { PollState::Password => {
write_handle.can_authenticate = false; write_handle.can_authenticate = false;
@ -575,7 +575,7 @@ impl MPDHandler {
write_handle.dirty_flag.store(true, Ordering::Relaxed); write_handle.dirty_flag.store(true, Ordering::Relaxed);
log( log(
"Failed to get readpicture", "Failed to get readpicture",
LogState::WARNING, LogState::Warning,
write_handle.log_level, write_handle.log_level,
); );
// Not setting error_text here since // Not setting error_text here since
@ -586,7 +586,7 @@ impl MPDHandler {
write_handle.dirty_flag.store(true, Ordering::Relaxed); write_handle.dirty_flag.store(true, Ordering::Relaxed);
log( log(
"Failed to get albumart", "Failed to get albumart",
LogState::WARNING, LogState::Warning,
write_handle.log_level, write_handle.log_level,
); );
write_handle.error_text = "Failed to get album art from MPD".into(); write_handle.error_text = "Failed to get album art from MPD".into();
@ -622,7 +622,7 @@ impl MPDHandler {
} else { } else {
log( log(
"Failed to parse current song position", "Failed to parse current song position",
LogState::WARNING, LogState::Warning,
write_handle.log_level, write_handle.log_level,
); );
} }
@ -635,7 +635,7 @@ impl MPDHandler {
} else { } else {
log( log(
"Failed to parse current song duration", "Failed to parse current song duration",
LogState::WARNING, LogState::Warning,
write_handle.log_level, write_handle.log_level,
); );
} }
@ -647,7 +647,7 @@ impl MPDHandler {
} else { } else {
log( log(
"Failed to parse album art byte size", "Failed to parse album art byte size",
LogState::WARNING, LogState::Warning,
write_handle.log_level, write_handle.log_level,
); );
} }
@ -658,7 +658,7 @@ impl MPDHandler {
} else { } else {
log( log(
"Failed to parse album art chunk byte size", "Failed to parse album art chunk byte size",
LogState::WARNING, LogState::Warning,
write_handle.log_level, write_handle.log_level,
); );
} }
@ -671,7 +671,7 @@ impl MPDHandler {
} else { } else {
log( log(
format!("Got unrecognized/ignored line: {}", line), format!("Got unrecognized/ignored line: {}", line),
LogState::WARNING, LogState::Warning,
write_handle.log_level, write_handle.log_level,
); );
} }
@ -683,7 +683,7 @@ impl MPDHandler {
saved.len(), saved.len(),
read_line_in_progress.len() read_line_in_progress.len()
), ),
LogState::WARNING, LogState::Warning,
write_handle.log_level, write_handle.log_level,
); );
*saved_str = read_line_in_progress; *saved_str = read_line_in_progress;
@ -725,7 +725,7 @@ impl MPDHandler {
} else if let Err(e) = write_result { } else if let Err(e) = write_result {
log( log(
format!("Failed to send password for authentication: {}", e), format!("Failed to send password for authentication: {}", e),
LogState::ERROR, LogState::Error,
write_handle.log_level, write_handle.log_level,
); );
} }
@ -740,7 +740,7 @@ impl MPDHandler {
} else if let Err(e) = write_result { } else if let Err(e) = write_result {
log( log(
format!("Failed to request song info over stream: {}", e), format!("Failed to request song info over stream: {}", e),
LogState::ERROR, LogState::Error,
write_handle.log_level, write_handle.log_level,
); );
} }
@ -756,7 +756,7 @@ impl MPDHandler {
} else if let Err(e) = write_result { } else if let Err(e) = write_result {
log( log(
format!("Failed to request status over stream: {}", e), format!("Failed to request status over stream: {}", e),
LogState::ERROR, LogState::Error,
write_handle.log_level, write_handle.log_level,
); );
} }
@ -775,7 +775,7 @@ impl MPDHandler {
} else if let Err(e) = write_result { } else if let Err(e) = write_result {
log( log(
format!("Failed to request album art: {}", e), format!("Failed to request album art: {}", e),
LogState::ERROR, LogState::Error,
write_handle.log_level, write_handle.log_level,
); );
} }
@ -788,7 +788,7 @@ impl MPDHandler {
} else if let Err(e) = write_result { } else if let Err(e) = write_result {
log( log(
format!("Failed to request album art in dir: {}", e), format!("Failed to request album art in dir: {}", e),
LogState::ERROR, LogState::Error,
write_handle.log_level, write_handle.log_level,
); );
} }
@ -823,7 +823,7 @@ impl MPDHandlerState {
self.art_data_size, self.art_data_size,
self.art_data.len() self.art_data.len()
), ),
LogState::DEBUG, LogState::Debug,
self.log_level, self.log_level,
); );
self.art_data_size != 0 && self.art_data.len() == self.art_data_size self.art_data_size != 0 && self.art_data.len() == self.art_data_size