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")]
use bindgen;
use std::env;
#[cfg(feature = "unicode_support")]
use std::path::PathBuf;
#[cfg(not(feature = "unicode_support"))]

View 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,8 +135,7 @@ fn string_to_text(
current_fragment.font = Some(font);
}
current_fragment.text.push(c);
} else {
if let Some(idx) = idx_opt {
} 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 {
@ -165,7 +165,6 @@ fn string_to_text(
}
current_fragment.text.push(c);
}
}
prev_is_ascii = false;
}
}

View 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,

View 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,8 +234,8 @@ 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()
@ -242,7 +245,6 @@ mod ffi {
}
}
}
}
Ok(vec)
}
@ -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)?;

View 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(