Fix clippy warnings

This commit is contained in:
Stephen Seo 2023-01-29 14:50:26 +09:00
parent e025a48735
commit c902f0fcf3
5 changed files with 32 additions and 37 deletions

View file

@ -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

@ -112,7 +112,7 @@ fn string_to_text(
} }
} else { } else {
log( log(
format!("Failed to find font for {}", c), format!("Failed to find font for {c}"),
debug_log::LogState::Error, debug_log::LogState::Error,
debug_log::LogLevel::Error, debug_log::LogLevel::Error,
); );
@ -234,7 +234,7 @@ impl MPDDisplay {
is_initialized: false, is_initialized: false,
is_authenticated: false, is_authenticated: false,
notice_text: Text::default(), notice_text: Text::default(),
poll_instant: Instant::now() - POLL_TIME, poll_instant: Instant::now().checked_sub(POLL_TIME).unwrap(),
shared: None, shared: None,
password_entered: false, password_entered: false,
dirty_flag: None, dirty_flag: None,
@ -411,13 +411,10 @@ impl MPDDisplay {
let reader = ImageReader::new(Cursor::new(image_ref)); let reader = ImageReader::new(Cursor::new(image_ref));
let guessed_reader = reader let guessed_reader = reader
.with_guessed_format() .with_guessed_format()
.map_err(|e| format!("Error: Failed to guess format of album art image: {}", e)); .map_err(|e| format!("Error: Failed to guess format of album art image: {e}"));
if let Ok(reader) = guessed_reader { if let Ok(reader) = guessed_reader {
reader.decode().map_err(|e| { reader.decode().map_err(|e| {
format!( format!("Error: Failed to decode album art image (guessed format): {e}")
"Error: Failed to decode album art image (guessed format): {}",
e
)
}) })
} else { } else {
// Convert Ok(_) to Ok(DynamicImage) which will never be used // Convert Ok(_) to Ok(DynamicImage) which will never be used
@ -427,7 +424,7 @@ impl MPDDisplay {
} else { } else {
ImageReader::with_format(Cursor::new(image_ref), image_format) 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(
@ -732,8 +729,7 @@ impl EventHandler for MPDDisplay {
if !self.is_valid { if !self.is_valid {
if let Err(mpd_handler_error) = &self.mpd_handler { if let Err(mpd_handler_error) = &self.mpd_handler {
return Err(GameError::EventLoopError(format!( return Err(GameError::EventLoopError(format!(
"Failed to initialize MPDHandler: {}", "Failed to initialize MPDHandler: {mpd_handler_error}"
mpd_handler_error
))); )));
} else { } else {
return Err(GameError::EventLoopError( return Err(GameError::EventLoopError(

View file

@ -131,7 +131,7 @@ fn main() -> Result<(), String> {
display.text_input_event(ctx, ch).ok(); display.text_input_event(ctx, ch).ok();
} }
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,
), ),
@ -162,7 +162,7 @@ fn main() -> Result<(), String> {
ggez::timer::yield_now(); ggez::timer::yield_now();
} }
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

@ -274,9 +274,9 @@ impl MPDHandler {
did_check_overtime: false, did_check_overtime: false,
force_get_status: false, force_get_status: false,
force_get_current_song: false, force_get_current_song: false,
song_title_get_time: Instant::now() - Duration::from_secs(10), song_title_get_time: Instant::now().checked_sub(Duration::from_secs(10)).unwrap(),
song_pos_get_time: Instant::now() - Duration::from_secs(10), song_pos_get_time: Instant::now().checked_sub(Duration::from_secs(10)).unwrap(),
song_length_get_time: Instant::now() - Duration::from_secs(10), song_length_get_time: Instant::now().checked_sub(Duration::from_secs(10)).unwrap(),
self_thread: None, self_thread: None,
dirty_flag: Arc::new(AtomicBool::new(true)), dirty_flag: Arc::new(AtomicBool::new(true)),
stop_flag: Arc::new(AtomicBool::new(false)), stop_flag: Arc::new(AtomicBool::new(false)),
@ -426,13 +426,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,
); );
@ -477,7 +477,7 @@ impl MPDHandler {
let read_result = write_handle.stream.read(buf); let read_result = write_handle.stream.read(buf);
if let Err(io_err) = read_result { if let Err(io_err) = read_result {
if io_err.kind() != io::ErrorKind::WouldBlock { if io_err.kind() != io::ErrorKind::WouldBlock {
return Err(format!("TCP stream error: {}", io_err)); return Err(format!("TCP stream error: {io_err}"));
} else { } else {
return Ok(()); return Ok(());
} }
@ -649,9 +649,9 @@ impl MPDHandler {
MPDPlayState::Paused MPDPlayState::Paused
}; };
write_handle.error_text.clear(); write_handle.error_text.clear();
write!(&mut write_handle.error_text, "MPD has {:?}", got_mpd_state).ok(); write!(&mut write_handle.error_text, "MPD has {got_mpd_state:?}").ok();
log( log(
format!("MPD is {:?}", got_mpd_state), format!("MPD is {got_mpd_state:?}"),
LogState::Warning, LogState::Warning,
write_handle.log_level, write_handle.log_level,
); );
@ -736,7 +736,7 @@ impl MPDHandler {
write_handle.art_data_type = line.split_off(6); write_handle.art_data_type = line.split_off(6);
} 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,
); );
@ -799,12 +799,12 @@ impl MPDHandler {
let p = write_handle.password.clone(); let p = write_handle.password.clone();
let write_result = write_handle let write_result = write_handle
.stream .stream
.write(format!("password {}\n", p).as_bytes()); .write(format!("password {p}\n").as_bytes());
if write_result.is_ok() { if write_result.is_ok() {
write_handle.poll_state = PollState::Password; write_handle.poll_state = PollState::Password;
} 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,
); );
@ -820,7 +820,7 @@ impl MPDHandler {
write_handle.poll_state = PollState::CurrentSong; write_handle.poll_state = PollState::CurrentSong;
} 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,
); );
@ -836,7 +836,7 @@ impl MPDHandler {
write_handle.poll_state = PollState::Status; write_handle.poll_state = PollState::Status;
} 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,
); );
@ -848,14 +848,14 @@ impl MPDHandler {
let title = write_handle.current_song_filename.clone(); let title = write_handle.current_song_filename.clone();
let art_data_length = write_handle.art_data.len(); let art_data_length = write_handle.art_data.len();
if write_handle.can_get_album_art { if write_handle.can_get_album_art {
let write_result = write_handle.stream.write( let write_result = write_handle
format!("readpicture \"{}\" {}\n", title, art_data_length).as_bytes(), .stream
); .write(format!("readpicture \"{title}\" {art_data_length}\n").as_bytes());
if write_result.is_ok() { if write_result.is_ok() {
write_handle.poll_state = PollState::ReadPicture; write_handle.poll_state = PollState::ReadPicture;
} 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,
); );
@ -863,12 +863,12 @@ impl MPDHandler {
} else if write_handle.can_get_album_art_in_dir { } else if write_handle.can_get_album_art_in_dir {
let write_result = write_handle let write_result = write_handle
.stream .stream
.write(format!("albumart \"{}\" {}\n", title, art_data_length).as_bytes()); .write(format!("albumart \"{title}\" {art_data_length}\n").as_bytes());
if write_result.is_ok() { if write_result.is_ok() {
write_handle.poll_state = PollState::ReadPictureInDir; write_handle.poll_state = PollState::ReadPictureInDir;
} 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,
); );

View file

@ -67,8 +67,7 @@ mod ffi {
return Err(String::from("Failed to FcFontMatch (FcResult is not FcResultMatch; result_pattern is not null)")); return Err(String::from("Failed to FcFontMatch (FcResult is not FcResultMatch; result_pattern is not null)"));
} else { } else {
return Err(format!( return Err(format!(
"Failed to FcFontMatch (FcResult is not FcResultMatch; {:?})", "Failed to FcFontMatch (FcResult is not FcResultMatch; {result:?})"
result
)); ));
} }
} else if result_pattern.is_null() { } else if result_pattern.is_null() {