diff --git a/build.rs b/build.rs index f393618..702c52b 100644 --- a/build.rs +++ b/build.rs @@ -1,6 +1,6 @@ #[cfg(feature = "unicode_support")] -use bindgen; use std::env; +#[cfg(feature = "unicode_support")] use std::path::PathBuf; #[cfg(not(feature = "unicode_support"))] diff --git a/src/display.rs b/src/display.rs index 62c4ef2..c176698 100644 --- a/src/display.rs +++ b/src/display.rs @@ -51,10 +51,11 @@ fn seconds_to_time(seconds: f64) -> String { } #[cfg(not(feature = "unicode_support"))] +#[allow(clippy::ptr_arg)] fn string_to_text( string: String, - loaded_fonts: &mut Vec<(PathBuf, Font)>, - ctx: &mut Context, + _loaded_fonts: &mut Vec<(PathBuf, Font)>, + _ctx: &mut Context, ) -> Text { Text::new(TextFragment::from(string)) } @@ -134,37 +135,35 @@ fn string_to_text( current_fragment.font = Some(font); } current_fragment.text.push(c); - } else { - if let Some(idx) = idx_opt { - let font = loaded_fonts[idx].1; - if let Some(current_font) = current_fragment.font { - if current_font == font { - current_fragment.text.push(c); - } else { - if !current_fragment.text.is_empty() { - text.add(current_fragment); - current_fragment = Default::default(); - } - current_fragment.text.push(c); - current_fragment.font = Some(font); - } - } else if current_fragment.text.is_empty() { + } else if let Some(idx) = idx_opt { + let font = loaded_fonts[idx].1; + if let Some(current_font) = current_fragment.font { + if current_font == font { current_fragment.text.push(c); - current_fragment.font = Some(font); } else { - text.add(current_fragment); - current_fragment = Default::default(); - + if !current_fragment.text.is_empty() { + text.add(current_fragment); + current_fragment = Default::default(); + } current_fragment.text.push(c); current_fragment.font = Some(font); } - } else { - if !current_fragment.text.is_empty() && current_fragment.font.is_some() { - text.add(current_fragment); - current_fragment = Default::default(); - } + } else if current_fragment.text.is_empty() { current_fragment.text.push(c); + current_fragment.font = Some(font); + } else { + text.add(current_fragment); + current_fragment = Default::default(); + + current_fragment.text.push(c); + current_fragment.font = Some(font); } + } else { + if !current_fragment.text.is_empty() && current_fragment.font.is_some() { + text.add(current_fragment); + current_fragment = Default::default(); + } + current_fragment.text.push(c); } prev_is_ascii = false; } diff --git a/src/mpd_handler.rs b/src/mpd_handler.rs index 925810a..fc1c8f4 100644 --- a/src/mpd_handler.rs +++ b/src/mpd_handler.rs @@ -1,5 +1,6 @@ use crate::debug_log::{log, LogLevel, LogState}; -use std::io::{self, Read, Write}; +use std::fmt::Write; +use std::io::{self, Read, Write as IOWrite}; use std::net::{IpAddr, Ipv4Addr, SocketAddr, TcpStream}; use std::str::FromStr; use std::sync::atomic::{AtomicBool, Ordering}; @@ -44,6 +45,8 @@ pub struct MPDHandler { state: Arc>, } +type SelfThreadT = Option>>>>; + pub struct MPDHandlerState { art_data: Vec, art_data_size: usize, @@ -70,7 +73,7 @@ pub struct MPDHandlerState { song_title_get_time: Instant, song_pos_get_time: Instant, song_length_get_time: Instant, - self_thread: Option>>>>, + self_thread: SelfThreadT, dirty_flag: Arc, pub stop_flag: Arc, log_level: LogLevel, @@ -320,6 +323,7 @@ impl MPDHandler { Err(()) } + #[allow(dead_code)] pub fn is_dirty(&self) -> Result { if let Ok(write_lock) = self.state.try_write() { return Ok(write_lock.dirty_flag.swap(false, Ordering::Relaxed)); @@ -328,6 +332,7 @@ impl MPDHandler { Err(()) } + #[allow(dead_code)] pub fn force_get_current_song(&self) { loop { if let Ok(mut write_lock) = self.state.try_write() { @@ -349,6 +354,7 @@ impl MPDHandler { Ok(!read_handle.can_authenticate) } + #[allow(dead_code)] pub fn has_image_data(&self) -> Result { let read_handle = self.state.try_read().map_err(|_| ())?; Ok(read_handle.is_art_data_ready()) @@ -638,9 +644,7 @@ impl MPDHandler { MPDPlayState::Paused }; write_handle.error_text.clear(); - write_handle - .error_text - .push_str(&format!("MPD has {:?}", got_mpd_state)); + write!(&mut write_handle.error_text, "MPD has {:?}", got_mpd_state).ok(); log( format!("MPD is {:?}", got_mpd_state), LogState::Warning, diff --git a/src/unicode_support/fontconfig.rs b/src/unicode_support/fontconfig.rs index 1b6f19d..d1e8037 100644 --- a/src/unicode_support/fontconfig.rs +++ b/src/unicode_support/fontconfig.rs @@ -9,6 +9,7 @@ mod ffi { #![allow(non_snake_case)] #![allow(dead_code)] #![allow(deref_nullptr)] + #![allow(clippy::redundant_static_lifetimes)] include!(concat!(env!("OUT_DIR"), "/unicode_support_bindings.rs")); } @@ -37,6 +38,7 @@ mod ffi { } } + #[allow(dead_code)] pub fn get(&mut self) -> *mut bindgen::FcConfig { self.config } @@ -97,6 +99,7 @@ mod ffi { } impl FcCharSetWr { + #[allow(dead_code)] pub fn new_with_str(s: &str) -> Result { let charset; unsafe { @@ -231,15 +234,14 @@ mod ffi { i, &mut value as *mut bindgen::FcValue, ) == bindgen::_FcResult_FcResultMatch + && value.type_ == bindgen::_FcType_FcTypeString { - if value.type_ == bindgen::_FcType_FcTypeString { - let cs = CStr::from_ptr(value.u.s as *const i8); - vec.push( - cs.to_str() - .map_err(|_| String::from("Failed to convert CStr to String"))? - .to_owned(), - ); - } + let cs = CStr::from_ptr(value.u.s as *const i8); + vec.push( + cs.to_str() + .map_err(|_| String::from("Failed to convert CStr to String"))? + .to_owned(), + ); } } } @@ -295,6 +297,7 @@ mod ffi { } } +#[allow(dead_code)] pub fn get_matching_font_from_str(s: &str) -> Result { let mut config = ffi::FcConfigWr::new()?; let mut charset = ffi::FcCharSetWr::new_with_str(s)?; diff --git a/src/unicode_support/freetype.rs b/src/unicode_support/freetype.rs index 6a2ae46..4eb07b7 100644 --- a/src/unicode_support/freetype.rs +++ b/src/unicode_support/freetype.rs @@ -44,6 +44,8 @@ mod ffi { pub struct FTOpenArgs { args: FT_Open_Args, + // "args" has a pointer to the CString in "pathname", so it must be kept + #[allow(dead_code)] pathname: Option, } @@ -55,13 +57,13 @@ mod ffi { ); let args = FT_Open_Args { flags: FT_OPEN_PATHNAME, - memory_base: 0 as *const u8, + memory_base: std::ptr::null::(), memory_size: 0, pathname: cstring.as_ptr() as *mut i8, - stream: 0 as *mut FT_StreamRec_, - driver: 0 as *mut FT_ModuleRec_, + stream: std::ptr::null_mut::(), + driver: std::ptr::null_mut::(), num_params: 0, - params: 0 as *mut FT_Parameter_, + params: std::ptr::null_mut::(), }; FTOpenArgs { @@ -71,6 +73,7 @@ mod ffi { } } + #[allow(dead_code)] pub fn get_args(&self) -> FT_Open_Args { self.args } @@ -98,7 +101,6 @@ mod ffi { pub fn new(library: &FTLibrary, args: &mut FTOpenArgs) -> Result { let mut faces = FTFaces { faces: Vec::new() }; unsafe { - let count; let mut face: FT_Face = 0 as FT_Face; // first get number of faces let mut result = FT_Open_Face( @@ -111,7 +113,7 @@ mod ffi { FT_Done_Face(face); return Err(()); } - count = (*face).num_faces; + let count = (*face).num_faces; for i in 0..count { result = FT_Open_Face(