Fix/inhibit clippy warnings

This commit is contained in:
Stephen Seo 2022-08-01 13:37:13 +09:00
parent 1bb5dd79d0
commit 5f45f802b6
5 changed files with 54 additions and 46 deletions

View file

@ -1,6 +1,6 @@
#[cfg(feature = "unicode_support")] #[cfg(feature = "unicode_support")]
use bindgen;
use std::env; use std::env;
#[cfg(feature = "unicode_support")]
use std::path::PathBuf; use std::path::PathBuf;
#[cfg(not(feature = "unicode_support"))] #[cfg(not(feature = "unicode_support"))]

View file

@ -51,10 +51,11 @@ fn seconds_to_time(seconds: f64) -> String {
} }
#[cfg(not(feature = "unicode_support"))] #[cfg(not(feature = "unicode_support"))]
#[allow(clippy::ptr_arg)]
fn string_to_text( fn string_to_text(
string: String, string: String,
loaded_fonts: &mut Vec<(PathBuf, Font)>, _loaded_fonts: &mut Vec<(PathBuf, Font)>,
ctx: &mut Context, _ctx: &mut Context,
) -> Text { ) -> Text {
Text::new(TextFragment::from(string)) Text::new(TextFragment::from(string))
} }
@ -134,37 +135,35 @@ fn string_to_text(
current_fragment.font = Some(font); current_fragment.font = Some(font);
} }
current_fragment.text.push(c); current_fragment.text.push(c);
} else { } else if let Some(idx) = idx_opt {
if let Some(idx) = idx_opt { let font = loaded_fonts[idx].1;
let font = loaded_fonts[idx].1; if let Some(current_font) = current_fragment.font {
if let Some(current_font) = current_fragment.font { if current_font == 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() {
current_fragment.text.push(c); current_fragment.text.push(c);
current_fragment.font = Some(font);
} else { } else {
text.add(current_fragment); if !current_fragment.text.is_empty() {
current_fragment = Default::default(); text.add(current_fragment);
current_fragment = Default::default();
}
current_fragment.text.push(c); current_fragment.text.push(c);
current_fragment.font = Some(font); current_fragment.font = Some(font);
} }
} else { } else if current_fragment.text.is_empty() {
if !current_fragment.text.is_empty() && current_fragment.font.is_some() {
text.add(current_fragment);
current_fragment = Default::default();
}
current_fragment.text.push(c); 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; prev_is_ascii = false;
} }

View file

@ -1,5 +1,6 @@
use crate::debug_log::{log, LogLevel, LogState}; 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::net::{IpAddr, Ipv4Addr, SocketAddr, TcpStream};
use std::str::FromStr; use std::str::FromStr;
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
@ -44,6 +45,8 @@ pub struct MPDHandler {
state: Arc<RwLock<MPDHandlerState>>, state: Arc<RwLock<MPDHandlerState>>,
} }
type SelfThreadT = Option<Arc<Mutex<thread::JoinHandle<Result<(), String>>>>>;
pub struct MPDHandlerState { pub struct MPDHandlerState {
art_data: Vec<u8>, art_data: Vec<u8>,
art_data_size: usize, art_data_size: usize,
@ -70,7 +73,7 @@ pub struct MPDHandlerState {
song_title_get_time: Instant, song_title_get_time: Instant,
song_pos_get_time: Instant, song_pos_get_time: Instant,
song_length_get_time: Instant, song_length_get_time: Instant,
self_thread: Option<Arc<Mutex<thread::JoinHandle<Result<(), String>>>>>, self_thread: SelfThreadT,
dirty_flag: Arc<AtomicBool>, dirty_flag: Arc<AtomicBool>,
pub stop_flag: Arc<AtomicBool>, pub stop_flag: Arc<AtomicBool>,
log_level: LogLevel, log_level: LogLevel,
@ -320,6 +323,7 @@ impl MPDHandler {
Err(()) Err(())
} }
#[allow(dead_code)]
pub fn is_dirty(&self) -> Result<bool, ()> { pub fn is_dirty(&self) -> Result<bool, ()> {
if let Ok(write_lock) = self.state.try_write() { if let Ok(write_lock) = self.state.try_write() {
return Ok(write_lock.dirty_flag.swap(false, Ordering::Relaxed)); return Ok(write_lock.dirty_flag.swap(false, Ordering::Relaxed));
@ -328,6 +332,7 @@ impl MPDHandler {
Err(()) Err(())
} }
#[allow(dead_code)]
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() {
@ -349,6 +354,7 @@ impl MPDHandler {
Ok(!read_handle.can_authenticate) Ok(!read_handle.can_authenticate)
} }
#[allow(dead_code)]
pub fn has_image_data(&self) -> Result<bool, ()> { pub fn has_image_data(&self) -> Result<bool, ()> {
let read_handle = self.state.try_read().map_err(|_| ())?; let read_handle = self.state.try_read().map_err(|_| ())?;
Ok(read_handle.is_art_data_ready()) Ok(read_handle.is_art_data_ready())
@ -638,9 +644,7 @@ impl MPDHandler {
MPDPlayState::Paused MPDPlayState::Paused
}; };
write_handle.error_text.clear(); write_handle.error_text.clear();
write_handle write!(&mut write_handle.error_text, "MPD has {:?}", got_mpd_state).ok();
.error_text
.push_str(&format!("MPD has {:?}", got_mpd_state));
log( log(
format!("MPD is {:?}", got_mpd_state), format!("MPD is {:?}", got_mpd_state),
LogState::Warning, LogState::Warning,

View file

@ -9,6 +9,7 @@ mod ffi {
#![allow(non_snake_case)] #![allow(non_snake_case)]
#![allow(dead_code)] #![allow(dead_code)]
#![allow(deref_nullptr)] #![allow(deref_nullptr)]
#![allow(clippy::redundant_static_lifetimes)]
include!(concat!(env!("OUT_DIR"), "/unicode_support_bindings.rs")); 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 { pub fn get(&mut self) -> *mut bindgen::FcConfig {
self.config self.config
} }
@ -97,6 +99,7 @@ mod ffi {
} }
impl FcCharSetWr { impl FcCharSetWr {
#[allow(dead_code)]
pub fn new_with_str(s: &str) -> Result<Self, String> { pub fn new_with_str(s: &str) -> Result<Self, String> {
let charset; let charset;
unsafe { unsafe {
@ -231,15 +234,14 @@ mod ffi {
i, i,
&mut value as *mut bindgen::FcValue, &mut value as *mut bindgen::FcValue,
) == bindgen::_FcResult_FcResultMatch ) == 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);
let cs = CStr::from_ptr(value.u.s as *const i8); vec.push(
vec.push( cs.to_str()
cs.to_str() .map_err(|_| String::from("Failed to convert CStr to String"))?
.map_err(|_| String::from("Failed to convert CStr to String"))? .to_owned(),
.to_owned(), );
);
}
} }
} }
} }
@ -295,6 +297,7 @@ mod ffi {
} }
} }
#[allow(dead_code)]
pub fn get_matching_font_from_str(s: &str) -> Result<PathBuf, String> { pub fn get_matching_font_from_str(s: &str) -> Result<PathBuf, String> {
let mut config = ffi::FcConfigWr::new()?; let mut config = ffi::FcConfigWr::new()?;
let mut charset = ffi::FcCharSetWr::new_with_str(s)?; let mut charset = ffi::FcCharSetWr::new_with_str(s)?;

View file

@ -44,6 +44,8 @@ mod ffi {
pub struct FTOpenArgs { pub struct FTOpenArgs {
args: FT_Open_Args, args: FT_Open_Args,
// "args" has a pointer to the CString in "pathname", so it must be kept
#[allow(dead_code)]
pathname: Option<CString>, pathname: Option<CString>,
} }
@ -55,13 +57,13 @@ mod ffi {
); );
let args = FT_Open_Args { let args = FT_Open_Args {
flags: FT_OPEN_PATHNAME, flags: FT_OPEN_PATHNAME,
memory_base: 0 as *const u8, memory_base: std::ptr::null::<u8>(),
memory_size: 0, memory_size: 0,
pathname: cstring.as_ptr() as *mut i8, pathname: cstring.as_ptr() as *mut i8,
stream: 0 as *mut FT_StreamRec_, stream: std::ptr::null_mut::<FT_StreamRec_>(),
driver: 0 as *mut FT_ModuleRec_, driver: std::ptr::null_mut::<FT_ModuleRec_>(),
num_params: 0, num_params: 0,
params: 0 as *mut FT_Parameter_, params: std::ptr::null_mut::<FT_Parameter_>(),
}; };
FTOpenArgs { FTOpenArgs {
@ -71,6 +73,7 @@ mod ffi {
} }
} }
#[allow(dead_code)]
pub fn get_args(&self) -> FT_Open_Args { pub fn get_args(&self) -> FT_Open_Args {
self.args self.args
} }
@ -98,7 +101,6 @@ mod ffi {
pub fn new(library: &FTLibrary, args: &mut FTOpenArgs) -> Result<FTFaces, ()> { pub fn new(library: &FTLibrary, args: &mut FTOpenArgs) -> Result<FTFaces, ()> {
let mut faces = FTFaces { faces: Vec::new() }; let mut faces = FTFaces { faces: Vec::new() };
unsafe { unsafe {
let count;
let mut face: FT_Face = 0 as FT_Face; let mut face: FT_Face = 0 as FT_Face;
// first get number of faces // first get number of faces
let mut result = FT_Open_Face( let mut result = FT_Open_Face(
@ -111,7 +113,7 @@ mod ffi {
FT_Done_Face(face); FT_Done_Face(face);
return Err(()); return Err(());
} }
count = (*face).num_faces; let count = (*face).num_faces;
for i in 0..count { for i in 0..count {
result = FT_Open_Face( result = FT_Open_Face(