]> git.seodisparate.com - mpd_info_screen/commitdiff
Fix/inhibit clippy warnings
authorStephen Seo <seo.disparate@gmail.com>
Mon, 1 Aug 2022 04:37:13 +0000 (13:37 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Mon, 1 Aug 2022 04:37:13 +0000 (13:37 +0900)
build.rs
src/display.rs
src/mpd_handler.rs
src/unicode_support/fontconfig.rs
src/unicode_support/freetype.rs

index f3936185372467cfe3fcb0d11d79805f96616afc..702c52b8fb6d3e9dd9d100b1613217babc87188f 100644 (file)
--- 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"))]
index 62c4ef28999dc9e2dadb499450be64c29bdf85ac..c1766983842cb95abebdbc2663c9f21e4459fb6d 100644 (file)
@@ -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.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();
-                    }
+                    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;
         }
index 925810a9699def7a5ef6cd2f8f0f8ca61c052414..fc1c8f45270f6f8180c7cdf7d94988371c16ac8a 100644 (file)
@@ -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<RwLock<MPDHandlerState>>,
 }
 
+type SelfThreadT = Option<Arc<Mutex<thread::JoinHandle<Result<(), String>>>>>;
+
 pub struct MPDHandlerState {
     art_data: Vec<u8>,
     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<Arc<Mutex<thread::JoinHandle<Result<(), String>>>>>,
+    self_thread: SelfThreadT,
     dirty_flag: Arc<AtomicBool>,
     pub stop_flag: Arc<AtomicBool>,
     log_level: LogLevel,
@@ -320,6 +323,7 @@ impl MPDHandler {
         Err(())
     }
 
+    #[allow(dead_code)]
     pub fn is_dirty(&self) -> Result<bool, ()> {
         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<bool, ()> {
         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,
index 1b6f19d4f889b5160b4c74337e8c5333a1e9a049..d1e8037e6c1fafaa24edaa9392d18500506bae3d 100644 (file)
@@ -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<Self, String> {
             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<PathBuf, String> {
     let mut config = ffi::FcConfigWr::new()?;
     let mut charset = ffi::FcCharSetWr::new_with_str(s)?;
index 6a2ae4695fe920e4a830839f33e638fe49c21904..4eb07b7be1a8f1f608faf3823b033e75b83582a9 100644 (file)
@@ -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<CString>,
     }
 
@@ -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::<u8>(),
                     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::<FT_StreamRec_>(),
+                    driver: std::ptr::null_mut::<FT_ModuleRec_>(),
                     num_params: 0,
-                    params: 0 as *mut FT_Parameter_,
+                    params: std::ptr::null_mut::<FT_Parameter_>(),
                 };
 
                 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<FTFaces, ()> {
             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(