From 9c87cc7cd992aa8d749845aabe73047cbe217786 Mon Sep 17 00:00:00 2001 From: David Cosby Date: Fri, 9 Feb 2024 16:06:40 -0700 Subject: [PATCH] applied clippy suggestions --- src/driver/buffers.rs | 5 +---- src/sled/meta.rs | 2 +- src/sled/positional.rs | 20 ++++++++++---------- src/sled/segmental.rs | 2 +- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/driver/buffers.rs b/src/driver/buffers.rs index 5c1273b..75106f6 100644 --- a/src/driver/buffers.rs +++ b/src/driver/buffers.rs @@ -156,10 +156,7 @@ impl BufferContainer { } fn deref_option(option: Option<&T>) -> Option { - match option { - Some(v) => Some(*v), - None => None, - } + option.map(|v| *v) } impl std::ops::Index<&str> for BufferContainer { diff --git a/src/sled/meta.rs b/src/sled/meta.rs index f9ec515..67deebd 100644 --- a/src/sled/meta.rs +++ b/src/sled/meta.rs @@ -61,7 +61,7 @@ impl Sled { let num_leds = leds.len(); let index_of_closest = leds .iter() - .min_by(|l, r| l.distance().partial_cmp(&&r.distance()).unwrap()) + .min_by(|l, r| l.distance().partial_cmp(&r.distance()).unwrap()) .unwrap() .index() as usize; diff --git a/src/sled/positional.rs b/src/sled/positional.rs index accf260..c160ad3 100644 --- a/src/sled/positional.rs +++ b/src/sled/positional.rs @@ -33,7 +33,7 @@ impl Sled { } pub fn get_closest(&self) -> &Led { - &self.leds[self.index_of_closest as usize] + &self.leds[self.index_of_closest] } pub fn get_closest_to(&self, pos: Vec2) -> &Led { @@ -42,7 +42,7 @@ impl Sled { } pub fn modulate_closest Rgb>(&mut self, color_rule: F) { - let led = &mut self.leds[self.index_of_closest as usize]; + let led = &mut self.leds[self.index_of_closest]; led.color = color_rule(led); } @@ -53,7 +53,7 @@ impl Sled { } pub fn set_closest(&mut self, color: Rgb) { - self.leds[self.index_of_closest as usize].color = color; + self.leds[self.index_of_closest].color = color; } pub fn set_closest_to(&mut self, pos: Vec2, color: Rgb) { @@ -68,37 +68,37 @@ impl Sled { .vertex_indices .iter() .map(|i| { - let vertex_pos = self.leds[*i as usize].position(); + let vertex_pos = self.leds[*i].position(); (*i, pos.distance_squared(vertex_pos)) }) .max_by(|a, b| a.1.partial_cmp(&b.1).unwrap()) .unwrap(); - index_of_furthest as usize + index_of_furthest } pub fn get_furthest(&self) -> &Led { - &self.leds[self.index_of_furthest as usize] + &self.leds[self.index_of_furthest] } pub fn get_furthest_from(&self, pos: Vec2) -> &Led { let index_of_furthest = self.get_index_of_furthest_from(pos); - &self.leds[index_of_furthest as usize] + &self.leds[index_of_furthest] } pub fn modulate_furthest Rgb>(&mut self, color_rule: F) { - let led = &mut self.leds[self.index_of_furthest as usize]; + let led = &mut self.leds[self.index_of_furthest]; led.color = color_rule(led); } pub fn modulate_furthest_from Rgb>(&mut self, pos: Vec2, color_rule: F) { let index_of_furthest = self.get_index_of_furthest_from(pos); - let led = &mut self.leds[index_of_furthest as usize]; + let led = &mut self.leds[index_of_furthest]; led.color = color_rule(led); } pub fn set_furthest(&mut self, color: Rgb) { - self.leds[self.index_of_furthest as usize].color = color; + self.leds[self.index_of_furthest].color = color; } pub fn set_furthest_from(&mut self, pos: Vec2, color: Rgb) { diff --git a/src/sled/segmental.rs b/src/sled/segmental.rs index 98db7ea..8269f97 100644 --- a/src/sled/segmental.rs +++ b/src/sled/segmental.rs @@ -155,7 +155,7 @@ impl Sled { .as_err(); } - self.leds[self.vertex_indices[vertex_index] as usize].color = color; + self.leds[self.vertex_indices[vertex_index]].color = color; Ok(()) }