address clippy lints (#267)

This commit is contained in:
vemoo 2021-12-06 16:34:01 +01:00 committed by GitHub
parent a4ba00b209
commit 0f7d175621
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 30 additions and 43 deletions

View file

@ -36,7 +36,7 @@ fn main() {
window.set_background_color(0, 0, 20); window.set_background_color(0, 0, 20);
while window.is_open() && !window.is_key_down(Key::Escape) { while window.is_open() && !window.is_key_down(Key::Escape) {
for i in 0..buffer.len() { for (i, pixel) in buffer.iter_mut().enumerate() {
let mut real = map((i % WIDTH) as f64, 0., WIDTH as f64, x_min, x_max); let mut real = map((i % WIDTH) as f64, 0., WIDTH as f64, x_min, x_max);
let mut imag = map((i / HEIGHT) as f64, 0., HEIGHT as f64, y_min, y_max); let mut imag = map((i / HEIGHT) as f64, 0., HEIGHT as f64, y_min, y_max);
@ -55,7 +55,7 @@ fn main() {
n += 1; n += 1;
} }
buffer[i] = fill(n); *pixel = fill(n);
} }
angle += 0.1; angle += 0.1;
@ -71,8 +71,8 @@ fn map(val: f64, start1: f64, stop1: f64, start2: f64, stop2: f64) -> f64 {
fn fill(n: u32) -> u32 { fn fill(n: u32) -> u32 {
if FRACTAL_DEPTH == n { if FRACTAL_DEPTH == n {
return 0x00; 0x00
} else { } else {
return n * 32 % 255; n * 32 % 255
} }
} }

View file

@ -66,9 +66,9 @@ fn main() {
let menu_handle = window.add_menu(&menu); let menu_handle = window.add_menu(&menu);
window.get_posix_menus().map(|menus| { if let Some(menus) = window.get_posix_menus() {
println!("Menus {:?}", menus); println!("Menus {:?}", menus);
}); }
let mut color_mul = 1; let mut color_mul = 1;
@ -79,7 +79,7 @@ fn main() {
} }
} }
window.is_menu_pressed().map(|menu_id| { if let Some(menu_id) = window.is_menu_pressed() {
match menu_id { match menu_id {
COLOR_0_ID => { COLOR_0_ID => {
color_mul = 0xfe0000; color_mul = 0xfe0000;
@ -98,7 +98,7 @@ fn main() {
} }
println!("Menu id {} pressed", menu_id); println!("Menu id {} pressed", menu_id);
}); }
window.get_keys().iter().for_each(|key| match key { window.get_keys().iter().for_each(|key| match key {
Key::W => println!("holding w!"), Key::W => println!("holding w!"),

View file

@ -42,7 +42,7 @@ fn main() {
} }
} }
window.get_mouse_pos(MouseMode::Discard).map(|(x, y)| { if let Some((x, y)) = window.get_mouse_pos(MouseMode::Discard) {
let screen_pos = ((y as usize) * (width / 2)) + x as usize; let screen_pos = ((y as usize) * (width / 2)) + x as usize;
if window.get_mouse_down(MouseButton::Left) { if window.get_mouse_down(MouseButton::Left) {
@ -52,11 +52,11 @@ fn main() {
if window.get_mouse_down(MouseButton::Right) { if window.get_mouse_down(MouseButton::Right) {
buffer[screen_pos] = 0; buffer[screen_pos] = 0;
} }
}); }
window.get_scroll_wheel().map(|scroll| { if let Some(scroll) = window.get_scroll_wheel() {
println!("Scrolling {} - {}", scroll.0, scroll.1); println!("Scrolling {} - {}", scroll.0, scroll.1);
}); }
// We unwrap here as we want this code to exit if it fails // We unwrap here as we want this code to exit if it fails
window window

View file

@ -19,11 +19,7 @@ impl Rect {
let xe = self.x + self.width; let xe = self.x + self.width;
let ye = self.y + self.height; let ye = self.y + self.height;
if (y >= self.y) && (y <= ye) && (x >= self.x) && (x <= xe) { (y >= self.y) && (y <= ye) && (x >= self.x) && (x <= xe)
true
} else {
false
}
} }
} }

View file

@ -33,17 +33,14 @@ impl KeyHandler {
} }
pub fn get_keys(&self) -> Vec<Key> { pub fn get_keys(&self) -> Vec<Key> {
let mut index: u16 = 0;
let mut keys: Vec<Key> = Vec::new(); let mut keys: Vec<Key> = Vec::new();
for i in self.keys.iter() { for (index, i) in self.keys.iter().enumerate() {
if *i { if *i {
unsafe { unsafe {
keys.push(mem::transmute(index as u8)); keys.push(mem::transmute(index as u8));
} }
} }
index += 1;
} }
keys keys
@ -74,10 +71,9 @@ impl KeyHandler {
} }
pub fn get_keys_pressed(&self, repeat: KeyRepeat) -> Vec<Key> { pub fn get_keys_pressed(&self, repeat: KeyRepeat) -> Vec<Key> {
let mut index: u16 = 0;
let mut keys: Vec<Key> = Vec::new(); let mut keys: Vec<Key> = Vec::new();
for i in self.keys.iter() { for (index, i) in self.keys.iter().enumerate() {
if *i { if *i {
unsafe { unsafe {
if Self::key_pressed(self, index as usize, repeat) { if Self::key_pressed(self, index as usize, repeat) {
@ -85,8 +81,6 @@ impl KeyHandler {
} }
} }
} }
index += 1;
} }
keys keys
@ -108,7 +102,7 @@ impl KeyHandler {
#[inline] #[inline]
pub fn is_key_down(&self, key: Key) -> bool { pub fn is_key_down(&self, key: Key) -> bool {
return self.keys[key as usize]; self.keys[key as usize]
} }
#[inline] #[inline]
@ -139,22 +133,22 @@ impl KeyHandler {
} }
} }
return false; false
} }
#[inline] #[inline]
pub fn is_key_pressed(&self, key: Key, repeat: KeyRepeat) -> bool { pub fn is_key_pressed(&self, key: Key, repeat: KeyRepeat) -> bool {
return Self::key_pressed(self, key as usize, repeat); Self::key_pressed(self, key as usize, repeat)
} }
#[inline] #[inline]
pub fn is_key_released(&self, key: Key) -> bool { pub fn is_key_released(&self, key: Key) -> bool {
let idx = key as usize; let idx = key as usize;
return self.is_key_index_released(idx); self.is_key_index_released(idx)
} }
#[inline] #[inline]
fn is_key_index_released(&self, idx: usize) -> bool { fn is_key_index_released(&self, idx: usize) -> bool {
return self.keys_prev[idx] && !self.keys[idx]; self.keys_prev[idx] && !self.keys[idx]
} }
} }

View file

@ -51,8 +51,6 @@ impl Menu {
} }
pub fn remove_item(&mut self, handle: &MenuItemHandle) { pub fn remove_item(&mut self, handle: &MenuItemHandle) {
self.internal self.internal.items.retain(|item| item.handle.0 != handle.0);
.items
.retain(|ref item| item.handle.0 != handle.0);
} }
} }

View file

@ -22,6 +22,7 @@ pub use common::Menu;
use std::os::raw; use std::os::raw;
// Differentiate between Wayland and X11 at run-time // Differentiate between Wayland and X11 at run-time
#[allow(clippy::large_enum_variant)]
pub enum Window { pub enum Window {
#[cfg(feature = "x11")] #[cfg(feature = "x11")]
X11(x11::Window), X11(x11::Window),
@ -131,7 +132,6 @@ impl Window {
pub fn topmost(&self, _topmost: bool) { pub fn topmost(&self, _topmost: bool) {
// We will just do nothing until it is implemented so that nothing breaks // We will just do nothing until it is implemented so that nothing breaks
()
} }
pub fn get_size(&self) -> (usize, usize) { pub fn get_size(&self) -> (usize, usize) {

View file

@ -260,7 +260,7 @@ impl DisplayInfo {
) )
}; };
tempfile tempfile
.write_all(&slice[..]) .write_all(slice)
.map_err(|e| Error::WindowCreate(format!("Io Error: {:?}", e)))?; .map_err(|e| Error::WindowCreate(format!("Io Error: {:?}", e)))?;
tempfile tempfile
.flush() .flush()
@ -311,7 +311,7 @@ impl DisplayInfo {
.map_err(|e| Error::WindowCreate(format!("Roundtrip failed: {:?}", e)))?; .map_err(|e| Error::WindowCreate(format!("Roundtrip failed: {:?}", e)))?;
// Give the buffer to the surface and commit // Give the buffer to the surface and commit
surface.attach(Some(&buffer), 0, 0); surface.attach(Some(buffer), 0, 0);
surface.damage(0, 0, i32::max_value(), i32::max_value()); surface.damage(0, 0, i32::max_value(), i32::max_value());
surface.commit(); surface.commit();
@ -386,7 +386,7 @@ impl DisplayInfo {
) )
}; };
fd.write_all(&slice[..])?; fd.write_all(slice)?;
fd.flush()?; fd.flush()?;
// Acknowledge the last configure event // Acknowledge the last configure event
@ -701,7 +701,7 @@ impl Window {
} }
pub fn remove_menu(&mut self, handle: MenuHandle) { pub fn remove_menu(&mut self, handle: MenuHandle) {
self.menus.retain(|ref menu| menu.handle != handle); self.menus.retain(|menu| menu.handle != handle);
} }
pub fn is_menu_pressed(&mut self) -> Option<usize> { pub fn is_menu_pressed(&mut self) -> Option<usize> {

View file

@ -176,7 +176,7 @@ impl DisplayInfo {
_context: context, _context: context,
cursor_lib, cursor_lib,
// the following are determined later... // the following are determined later...
cursors: [0 as xlib::Cursor; 8], cursors: [0; 8],
keyb_ext: false, keyb_ext: false,
wm_delete_window: 0, wm_delete_window: 0,
}) })
@ -397,8 +397,8 @@ impl Window {
let xim = (d.lib.XOpenIM)( let xim = (d.lib.XOpenIM)(
d.display, d.display,
0 as XrmDatabase, 0 as XrmDatabase,
0 as *mut c_char, ptr::null_mut::<c_char>(),
0 as *mut c_char, ptr::null_mut::<c_char>(),
); );
if (xim as usize) == 0 { if (xim as usize) == 0 {
return Err(Error::WindowCreate( return Err(Error::WindowCreate(
@ -569,7 +569,6 @@ impl Window {
match CString::new(title) { match CString::new(title) {
Err(_) => { Err(_) => {
println!("Unable to convert {} to c_string", title); println!("Unable to convert {} to c_string", title);
return;
} }
Ok(t) => unsafe { Ok(t) => unsafe {
@ -830,7 +829,7 @@ impl Window {
} }
pub fn remove_menu(&mut self, handle: MenuHandle) { pub fn remove_menu(&mut self, handle: MenuHandle) {
self.menus.retain(|ref menu| menu.handle != handle); self.menus.retain(|menu| menu.handle != handle);
} }
pub fn is_menu_pressed(&mut self) -> Option<usize> { pub fn is_menu_pressed(&mut self) -> Option<usize> {