Reduce cargo clippy warnings

This commit is contained in:
Kenny Levinsen
2020-04-22 01:31:22 +02:00
parent 300711affe
commit 319bcdd355
17 changed files with 168 additions and 188 deletions
+4 -4
View File
@@ -4,8 +4,8 @@ use crate::widgets::bar_widget::{BarWidget, BarWidgetImpl};
use alsa::mixer::{Mixer, Selem, SelemChannelId, SelemId};
const CARD_NAME: &'static str = "default";
const SELEM_NAME: &'static str = "Master";
const CARD_NAME: &str = "default";
const SELEM_NAME: &str = "Master";
const SELEM_ID: u32 = 0u32;
#[inline]
@@ -15,8 +15,8 @@ fn alsa_error_to_io_error(fail: &'static str, err: &alsa::Error) -> ::std::io::E
let errno = err
.errno()
.map(|errno| format!("; errno = {}", errno))
.unwrap_or(String::new());
return ::std::io::Error::new(kind, format!("{}: {}{}", fail, func, errno));
.unwrap_or_default();
::std::io::Error::new(kind, format!("{}: {}{}", fail, func, errno))
}
#[inline]
+5 -9
View File
@@ -158,7 +158,7 @@ impl PulseAudioClient {
match req {
PulseAudioClientRequest::GetDefaultDevice(s) => {
introspector.get_server_info(move |info| {
let _res = PulseAudioClient::server_info_callback(
PulseAudioClient::server_info_callback(
cl.clone(),
l.clone(),
info,
@@ -260,13 +260,12 @@ impl PulseAudioClient {
}
fn send(&self, request: PulseAudioClientRequest) -> Result<(), ::std::io::Error> {
let res = self.sender.send(request).map_err(|_e| {
self.sender.send(request).map_err(|_e| {
::std::io::Error::new(
::std::io::ErrorKind::Other,
"unable to send pulseaudio request",
)
});
res
})
}
fn server_info_callback<F>(s: Arc<Mutex<Self>>, listener: F, server_info: &ServerInfo)
@@ -371,10 +370,7 @@ impl PulseAudioSoundDevice {
cl.default_sink.to_string()
};
(*inner.lock().unwrap()).name = Some(name.clone());
let device = PulseAudioSoundDevice {
client: cl,
inner: inner,
};
let device = PulseAudioSoundDevice { client: cl, inner };
let (tx, rx) = channel();
{
let cl = client.lock().unwrap();
@@ -497,7 +493,7 @@ impl PulseAudio {
*dirty.lock().unwrap() = true;
sender.send(Cmd::Draw).unwrap();
})?;
Ok(Box::new(PulseAudio { device: device }))
Ok(Box::new(PulseAudio { device }))
})
}
}
+5 -9
View File
@@ -2,9 +2,10 @@ use crate::color::Color;
use crate::widget::WaitContext;
use crate::widgets::bar_widget::{BarWidget, BarWidgetImpl};
use std::fs;
use std::fs::OpenOptions;
use std::io::Write;
use std::io::{Error, ErrorKind};
use std::io::{Read, Write};
use std::path::{Path, PathBuf};
pub struct Backlight {
@@ -14,11 +15,9 @@ pub struct Backlight {
}
fn read_file_as_u64(path: &Path) -> Result<u64, Error> {
let mut file = OpenOptions::new().read(true).open(path)?;
let mut str = String::new();
file.read_to_string(&mut str)?;
str.pop();
str.parse::<u64>()
let mut s = fs::read_to_string(path)?;
s.pop();
s.parse::<u64>()
.map_err(|_e| Error::new(ErrorKind::Other, "unable to parse value"))
}
@@ -101,7 +100,6 @@ impl BarWidgetImpl for Backlight {
Ok(val) => val,
Err(err) => {
eprintln!("Error while trying to change brightness: {}", err);
()
}
}
}
@@ -111,7 +109,6 @@ impl BarWidgetImpl for Backlight {
Ok(val) => val,
Err(err) => {
eprintln!("Error while trying to change brightness: {}", err);
()
}
}
}
@@ -125,7 +122,6 @@ impl BarWidgetImpl for Backlight {
Ok(val) => val,
Err(err) => {
eprintln!("Error while trying to change brightness: {}", err);
()
}
}
}
+7 -7
View File
@@ -34,9 +34,9 @@ impl BarWidget {
Box::new(BarWidget {
bar_impl: w,
dirty: Arc::new(Mutex::new(true)),
font: font,
font,
font_size: font_size as u32,
length: length,
length,
})
}
@@ -53,10 +53,10 @@ impl BarWidget {
Ok(Box::new(BarWidget {
bar_impl: im,
dirty: dirty,
font: font,
dirty,
font,
font_size: font_size as u32,
length: length,
length,
}))
}
}
@@ -119,8 +119,8 @@ impl Widget for BarWidget {
(self.length - bar_off, self.font_size),
)?;
Ok(DrawReport {
width: width,
height: height,
width,
height,
damage: vec![buf.get_signed_bounds()],
full_damage: false,
})
+3 -5
View File
@@ -8,8 +8,6 @@ use std::sync::{Arc, Mutex};
use nix::poll::{PollFd, PollFlags};
use dbus;
fn get_upower_property(
con: &dbus::Connection,
device_path: &str,
@@ -44,7 +42,7 @@ struct DbusConnection(dbus::Connection);
impl std::convert::AsRef<dbus::Connection> for DbusConnection {
fn as_ref(&self) -> &dbus::Connection {
return &self.0;
&self.0
}
}
@@ -156,8 +154,8 @@ impl UpowerBattery {
con: DbusConnection(con),
dirty,
sender,
capacity: capacity,
state: state,
capacity,
state,
watch: fds[0],
})
}
+12 -12
View File
@@ -22,10 +22,10 @@ impl Calendar {
&self,
buf: &mut Buffer,
background_color: &Color,
orig: &NaiveDate,
time: &NaiveDate,
orig: NaiveDate,
time: NaiveDate,
) -> Result<(i32, i32, i32, i32), ::std::io::Error> {
let mut time = time.clone();
let mut time = time;
let mut y_off = 1;
let mut done = false;
@@ -153,7 +153,7 @@ impl Calendar {
}
impl Calendar {
pub fn new(time: &NaiveDateTime, font_size: f32, sections: u32) -> Box<Calendar> {
pub fn new(time: NaiveDateTime, font_size: f32, sections: u32) -> Box<Calendar> {
let mut calendar_cache = Font::new(&DEJAVUSANS_MONO, font_size * 2.0);
calendar_cache.add_str_to_cache("0123456789");
let mut month_cache = Font::new(&ROBOTO_REGULAR, font_size * 4.0);
@@ -166,12 +166,12 @@ impl Calendar {
cur_date: time.date(),
dirty: true,
offset: 0.0,
sections: sections,
sections,
font_size: font_size as u32,
calendar_cache: calendar_cache,
month_cache: month_cache,
year_cache: year_cache,
day_cache: day_cache,
calendar_cache,
month_cache,
year_cache,
day_cache,
})
}
}
@@ -233,7 +233,7 @@ impl Widget for Calendar {
}
let cal_pad = 7 * self.font_size * 3 + self.font_size * 5;
for idx in 0..self.sections {
self.draw_month(&mut buf.offset((cal_pad * idx, 0))?, ctx.bg, &time, &t)?;
self.draw_month(&mut buf.offset((cal_pad * idx, 0))?, ctx.bg, time, t)?;
t = if t.month() == 12 {
t.with_year(t.year() + 1).unwrap().with_month(1).unwrap()
@@ -242,8 +242,8 @@ impl Widget for Calendar {
};
}
Ok(DrawReport {
width: width,
height: height,
width,
height,
damage: vec![buf.get_signed_bounds()],
full_damage: false,
})
+7 -7
View File
@@ -11,14 +11,14 @@ pub struct Clock {
}
impl Clock {
pub fn new(time: &NaiveDateTime, size: f32) -> Box<Clock> {
pub fn new(time: NaiveDateTime, size: f32) -> Box<Clock> {
let mut clock_cache = Font::new(&ROBOTO_REGULAR, size);
clock_cache.add_str_to_cache("0123456789:");
Box::new(Clock {
cur_time: time.clone(),
clock_cache: clock_cache,
size: size,
cur_time: time,
clock_cache,
size,
})
}
}
@@ -54,7 +54,7 @@ impl Widget for Clock {
return Ok(DrawReport::empty(width, height));
}
self.cur_time = ctx.time.clone();
self.cur_time = ctx.time;
let buf = &mut ctx.buf.subdimensions((pos.0, pos.1, width, height))?;
buf.memset(ctx.bg);
@@ -70,8 +70,8 @@ impl Widget for Clock {
)?;
Ok(DrawReport {
width: width,
height: height,
width,
height,
damage: vec![(pos.0 as i32, pos.1 as i32, width as i32, height as i32)],
full_damage: false,
})
+7 -7
View File
@@ -11,15 +11,15 @@ pub struct Date {
}
impl Date {
pub fn new(time: &NaiveDateTime, size: f32) -> Box<Date> {
pub fn new(time: NaiveDateTime, size: f32) -> Box<Date> {
let mut date_cache = Font::new(&ROBOTO_REGULAR, size);
date_cache
.add_str_to_cache("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,/ ");
Box::new(Date {
cur_time: time.clone(),
date_cache: date_cache,
size: size,
cur_time: time,
date_cache,
size,
})
}
}
@@ -43,7 +43,7 @@ impl Widget for Date {
return Ok(DrawReport::empty(width, height));
}
self.cur_time = ctx.time.clone();
self.cur_time = ctx.time;
let buf = &mut ctx.buf.subdimensions((pos.0, pos.1, width, height))?;
buf.memset(ctx.bg);
@@ -61,8 +61,8 @@ impl Widget for Date {
)?;
Ok(DrawReport {
width: width,
height: height,
width,
height,
damage: vec![(pos.0 as i32, pos.1 as i32, width as i32, height as i32)],
full_damage: false,
})
+24 -26
View File
@@ -50,15 +50,15 @@ impl Launcher {
offset: 0,
font: RefCell::new(Font::new(&ROBOTO_REGULAR, font_size)),
font_size: font_size as u32,
length: length,
length,
dirty: true,
tx: listener,
})
}
fn draw_launcher(&self, buf: &mut Buffer, bg: &Color) -> Result<(), ::std::io::Error> {
let mut x_off = if self.input.len() > 0 {
let c = if self.matches.len() == 0 {
let mut x_off = if !self.input.is_empty() {
let c = if self.matches.is_empty() {
Color::new(1.0, 0.5, 0.5, 1.0)
} else {
Color::new(1.0, 1.0, 1.0, 1.0)
@@ -79,7 +79,7 @@ impl Launcher {
Ok(b) => b,
Err(_) => break,
};
let size = if idx == self.offset && self.input.len() > 0 {
let size = if idx == self.offset && !self.input.is_empty() {
let (_, indices) =
fuzzy_indices(&m.name.to_lowercase(), &self.input.to_lowercase())
.unwrap_or((0, vec![]));
@@ -122,7 +122,7 @@ impl Launcher {
.0
+ self.font_size / 4;
let x_off = if self.input.len() > 0 {
let x_off = if !self.input.is_empty() {
let dim = self.font.borrow_mut().auto_draw_text(
&mut buf.offset((x_off, 0))?,
bg,
@@ -160,7 +160,7 @@ impl Launcher {
.0
+ self.font_size / 4;
if self.input.len() > 0 {
if !self.input.is_empty() {
self.font.borrow_mut().auto_draw_text(
&mut buf.offset((x_off, 0))?,
bg,
@@ -175,8 +175,8 @@ impl Launcher {
fn calc(s: &str) -> Result<String, String> {
rcalc_lib::parse::eval(s, &mut rcalc_lib::parse::CalcState::new())
.map(|x| format!("{}", x).to_string())
.map_err(|x| format!("{}", x).to_string())
.map(|x| format!("{}", x))
.map_err(|x| format!("{}", x))
}
fn wlcopy(s: &str) -> Result<(), String> {
@@ -223,7 +223,7 @@ impl Matcher {
let mut m = self
.matches
.iter()
.map(|(key, ma)| (ma.clone(), key.clone()))
.map(|(key, ma)| (*ma, key.clone()))
.collect::<Vec<(i64, Desktop)>>();
m.sort_by(|(ma1, d1), (ma2, d2)| {
@@ -313,8 +313,8 @@ impl Widget for Launcher {
}?;
Ok(DrawReport {
width: width,
height: height,
width,
height,
damage: vec![buf.get_signed_bounds()],
full_damage: false,
})
@@ -330,7 +330,7 @@ impl Widget for Launcher {
match key {
keysyms::XKB_KEY_u if modifiers.ctrl => self.leave(),
keysyms::XKB_KEY_BackSpace => {
if self.input.len() > 0 {
if !self.input.is_empty() {
self.input = self.input[..self.input.len() - 1].to_string();
self.offset = 0;
self.result = None;
@@ -339,12 +339,11 @@ impl Widget for Launcher {
}
keysyms::XKB_KEY_Return => {
match self.input.chars().next() {
Some('=') => match self.result {
Some(ref v) => {
Some('=') => {
if let Some(ref v) = self.result {
let _ = wlcopy(&v);
}
None => (),
},
}
Some('!') => {
let _ = Command::new("sh")
.arg("-c")
@@ -367,24 +366,24 @@ impl Widget for Launcher {
&self.app_opener
};
let lexed = if prefix.len() > 0 {
let lexed = if !prefix.is_empty() {
let mut prefix = shlex::split(prefix).unwrap();
prefix.push(exec);
prefix
} else {
shlex::split(&exec).unwrap()
};
if lexed.len() > 0 {
if !lexed.is_empty() {
let _ =
Command::new(lexed[0].clone()).args(&lexed[1..]).spawn();
self.tx.send(Cmd::Exit).unwrap();
}
}
if let Some(url) = &d.url {
if self.url_opener.len() > 0 {
if !self.url_opener.is_empty() {
let mut lexed = shlex::split(&self.url_opener).unwrap();
lexed.push(url.to_string());
if lexed.len() > 0 {
if !lexed.is_empty() {
let _ = Command::new(lexed[0].clone())
.args(&lexed[1..])
.spawn();
@@ -397,26 +396,25 @@ impl Widget for Launcher {
};
}
keysyms::XKB_KEY_Right => {
if self.matches.len() > 0 && self.offset < self.matches.len() - 1 {
if !self.matches.is_empty() && self.offset < self.matches.len() - 1 {
self.offset += 1;
self.dirty = true;
}
}
keysyms::XKB_KEY_Left => {
if self.matches.len() > 0 && self.offset > 0 {
if !self.matches.is_empty() && self.offset > 0 {
self.offset -= 1;
self.dirty = true;
}
}
_ => match interpreted {
Some(v) => {
_ => {
if let Some(v) = interpreted {
self.input += &v;
self.offset = 0;
self.result = None;
self.dirty = true;
}
None => {}
},
}
}
}
fn mouse_click(&mut self, _: u32, _: (u32, u32)) {}