Fix most clippy warnings

This commit is contained in:
Stephen Seo 2021-12-30 22:31:59 +09:00
parent 336f338b32
commit f98dc899f1
3 changed files with 27 additions and 39 deletions

View file

@ -107,23 +107,18 @@ impl MPDDisplay {
} }
} }
fn init_mpd_handler(&mut self) -> () { fn init_mpd_handler(&mut self) {
self.mpd_handler = MPDHandler::new( self.mpd_handler = MPDHandler::new(
self.opts.host, self.opts.host,
self.opts.port, self.opts.port,
self.opts.password.clone().map_or(String::new(), |s| s), self.opts.password.clone().map_or(String::new(), |s| s),
self.opts.log_level, self.opts.log_level,
) )
.map_or_else(|_| None, |v| Some(v)); .map_or_else(|_| None, Some);
if self.mpd_handler.is_some() { if self.mpd_handler.is_some() {
self.is_initialized = true; self.is_initialized = true;
loop { loop {
self.dirty_flag = self self.dirty_flag = self.mpd_handler.as_ref().unwrap().get_dirty_flag().ok();
.mpd_handler
.as_ref()
.unwrap()
.get_dirty_flag()
.map_or(None, |f| Some(f));
if self.dirty_flag.is_some() { if self.dirty_flag.is_some() {
break; break;
} else { } else {
@ -145,7 +140,7 @@ impl MPDDisplay {
} }
} }
fn get_album_art_transform(&mut self, ctx: &mut Context, fill_scaled: bool) -> () { fn get_album_art_transform(&mut self, ctx: &mut Context, fill_scaled: bool) {
if fill_scaled { if fill_scaled {
if let Some(image) = &self.album_art { if let Some(image) = &self.album_art {
let screen_coords: Rect = graphics::screen_coordinates(ctx); let screen_coords: Rect = graphics::screen_coordinates(ctx);
@ -176,8 +171,7 @@ impl MPDDisplay {
} else { } else {
self.album_art_draw_transform = None; self.album_art_draw_transform = None;
} }
} else { } else if let Some(image) = &self.album_art {
if let Some(image) = &self.album_art {
let screen_coords: Rect = graphics::screen_coordinates(ctx); let screen_coords: Rect = graphics::screen_coordinates(ctx);
let art_rect: Rect = image.dimensions(); let art_rect: Rect = image.dimensions();
let offset_x: f32 = (screen_coords.w.abs() - art_rect.w.abs()) / 2.0f32; let offset_x: f32 = (screen_coords.w.abs() - art_rect.w.abs()) / 2.0f32;
@ -192,7 +186,6 @@ impl MPDDisplay {
self.album_art_draw_transform = None; self.album_art_draw_transform = None;
} }
} }
}
fn get_image_from_data(&mut self, ctx: &mut Context) -> Result<(), String> { fn get_image_from_data(&mut self, ctx: &mut Context) -> Result<(), String> {
let read_guard = self let read_guard = self
@ -507,7 +500,7 @@ impl EventHandler for MPDDisplay {
if self.is_valid && self.is_initialized && self.poll_instant.elapsed() > POLL_TIME { if self.is_valid && self.is_initialized && self.poll_instant.elapsed() > POLL_TIME {
self.poll_instant = Instant::now(); self.poll_instant = Instant::now();
if !self.dirty_flag.is_none() if self.dirty_flag.is_some()
&& self && self
.dirty_flag .dirty_flag
.as_ref() .as_ref()
@ -524,7 +517,7 @@ impl EventHandler for MPDDisplay {
.as_ref() .as_ref()
.unwrap() .unwrap()
.get_current_song_info() .get_current_song_info()
.map_or(None, |f| Some(f)); .ok();
if let Some(shared) = &self.shared { if let Some(shared) = &self.shared {
if self.notice_text.contents() != shared.error_text { if self.notice_text.contents() != shared.error_text {
self.notice_text = Text::new(TextFragment::new(shared.error_text.clone())); self.notice_text = Text::new(TextFragment::new(shared.error_text.clone()));
@ -682,7 +675,7 @@ impl EventHandler for MPDDisplay {
if keycode == event::KeyCode::Back { if keycode == event::KeyCode::Back {
let s: String = self.notice_text.contents(); let s: String = self.notice_text.contents();
if s.ends_with("*") { if s.ends_with('*') {
self.notice_text = Text::new(TextFragment::new(s[0..(s.len() - 1)].to_owned())); self.notice_text = Text::new(TextFragment::new(s[0..(s.len() - 1)].to_owned()));
} }
@ -692,12 +685,10 @@ impl EventHandler for MPDDisplay {
} else if keycode == event::KeyCode::Return { } else if keycode == event::KeyCode::Return {
self.password_entered = true; self.password_entered = true;
} }
} else { } else if keycode == event::KeyCode::H {
if keycode == event::KeyCode::H {
self.hide_text = true; self.hide_text = true;
} }
} }
}
fn key_up_event( fn key_up_event(
&mut self, &mut self,

View file

@ -92,13 +92,10 @@ fn main() -> Result<(), String> {
}, },
is_synthetic: _, is_synthetic: _,
} => { } => {
match keycode { if keycode == event::KeyCode::Escape {
event::KeyCode::Escape => {
*control_flow = ControlFlow::Exit; *control_flow = ControlFlow::Exit;
return; return;
} }
_ => (),
}
if state == ElementState::Pressed { if state == ElementState::Pressed {
display.key_down_event(ctx, keycode, modifiers_state.into(), false); display.key_down_event(ctx, keycode, modifiers_state.into(), false);
} else { } else {

View file

@ -317,7 +317,7 @@ impl MPDHandler {
Err(()) Err(())
} }
pub fn force_get_current_song(&self) -> () { pub fn force_get_current_song(&self) {
loop { loop {
if let Ok(mut write_lock) = self.state.try_write() { if let Ok(mut write_lock) = self.state.try_write() {
write_lock.force_get_current_song = true; write_lock.force_get_current_song = true;
@ -343,8 +343,8 @@ impl MPDHandler {
Ok(read_handle.is_art_data_ready()) Ok(read_handle.is_art_data_ready())
} }
pub fn get_state_read_guard<'a>(&'a self) -> Result<RwLockReadGuard<'a, MPDHandlerState>, ()> { pub fn get_state_read_guard(&self) -> Result<RwLockReadGuard<'_, MPDHandlerState>, ()> {
Ok(self.state.try_read().map_err(|_| ())?) self.state.try_read().map_err(|_| ())
} }
pub fn stop_thread(&self) -> Result<(), ()> { pub fn stop_thread(&self) -> Result<(), ()> {