From b96938fecf1619fddd0e236620cac0096da9b650 Mon Sep 17 00:00:00 2001 From: Chloe Brett Date: Fri, 25 Apr 2025 11:39:25 +1000 Subject: [PATCH] Fix several clippy lints in dasp_graph. --- dasp_graph/src/buffer.rs | 2 +- dasp_graph/src/lib.rs | 20 ++++++++------------ dasp_graph/src/node/boxed.rs | 12 ++++++------ dasp_graph/src/node/delay.rs | 2 +- dasp_graph/src/node/mod.rs | 2 +- dasp_graph/src/node/pass.rs | 2 +- dasp_graph/src/node/signal.rs | 7 +++---- 7 files changed, 21 insertions(+), 26 deletions(-) diff --git a/dasp_graph/src/buffer.rs b/dasp_graph/src/buffer.rs index aed0a7b6..0accd65f 100644 --- a/dasp_graph/src/buffer.rs +++ b/dasp_graph/src/buffer.rs @@ -41,7 +41,7 @@ impl fmt::Debug for Buffer { impl PartialEq for Buffer { fn eq(&self, other: &Self) -> bool { - &self[..] == &other[..] + self[..] == other[..] } } diff --git a/dasp_graph/src/lib.rs b/dasp_graph/src/lib.rs index 2dcb145e..16c4f7c2 100644 --- a/dasp_graph/src/lib.rs +++ b/dasp_graph/src/lib.rs @@ -215,8 +215,10 @@ where where G::Map: Default, { - let mut dfs_post_order = DfsPostOrder::default(); - dfs_post_order.stack = Vec::with_capacity(max_nodes); + let dfs_post_order = DfsPostOrder { + stack: Vec::with_capacity(max_nodes), + ..Default::default() + }; let inputs = Vec::with_capacity(max_nodes); Self { dfs_post_order, @@ -346,29 +348,23 @@ where /// Produce an iterator yielding IDs for all **source** nodes within the graph. /// /// A node is considered to be a source node if it has no incoming edges. -pub fn sources<'a, G>(g: &'a G) -> impl 'a + Iterator +pub fn sources(g: &G) -> impl '_ + Iterator where G: IntoNeighborsDirected + NodeCount + NodeIndexable, { (0..g.node_count()) .map(move |ix| g.from_index(ix)) - .filter_map(move |id| match g.neighbors_directed(id, Incoming).next() { - None => Some(id), - _ => None, - }) + .filter(move |id| g.neighbors_directed(*id, Incoming).next().is_none()) } /// Produce an iterator yielding IDs for all **sink** nodes within the graph. /// /// A node is considered to be a **sink** node if it has no outgoing edges. -pub fn sinks<'a, G>(g: &'a G) -> impl 'a + Iterator +pub fn sinks(g: &G) -> impl '_ + Iterator where G: IntoNeighborsDirected + NodeCount + NodeIndexable, { (0..g.node_count()) .map(move |ix| g.from_index(ix)) - .filter_map(move |id| match g.neighbors_directed(id, Outgoing).next() { - None => Some(id), - _ => None, - }) + .filter(move |id| g.neighbors_directed(*id, Outgoing).next().is_none()) } diff --git a/dasp_graph/src/node/boxed.rs b/dasp_graph/src/node/boxed.rs index 7501d555..7e737530 100644 --- a/dasp_graph/src/node/boxed.rs +++ b/dasp_graph/src/node/boxed.rs @@ -72,15 +72,15 @@ where } } -impl Into> for BoxedNode { - fn into(self) -> Box { - self.0 +impl From for Box { + fn from(val: BoxedNode) -> Self { + val.0 } } -impl Into> for BoxedNodeSend { - fn into(self) -> Box { - self.0 +impl From for Box { + fn from(val: BoxedNodeSend) -> Self { + val.0 } } diff --git a/dasp_graph/src/node/delay.rs b/dasp_graph/src/node/delay.rs index 8e18d6b4..91fa694d 100644 --- a/dasp_graph/src/node/delay.rs +++ b/dasp_graph/src/node/delay.rs @@ -15,7 +15,7 @@ where { fn process(&mut self, inputs: &[Input], output: &mut [Buffer]) { // Retrieve the single input, ignore any others. - let input = match inputs.get(0) { + let input = match inputs.first() { Some(input) => input, None => return, }; diff --git a/dasp_graph/src/node/mod.rs b/dasp_graph/src/node/mod.rs index a9d52625..b4a89bbb 100644 --- a/dasp_graph/src/node/mod.rs +++ b/dasp_graph/src/node/mod.rs @@ -126,7 +126,7 @@ impl fmt::Debug for Input { } } -impl<'a, T> Node for &'a mut T +impl Node for &mut T where T: Node + ?Sized, { diff --git a/dasp_graph/src/node/pass.rs b/dasp_graph/src/node/pass.rs index 8872719a..18e6af06 100644 --- a/dasp_graph/src/node/pass.rs +++ b/dasp_graph/src/node/pass.rs @@ -12,7 +12,7 @@ pub struct Pass; impl Node for Pass { fn process(&mut self, inputs: &[Input], output: &mut [Buffer]) { - let input = match inputs.get(0) { + let input = match inputs.first() { None => return, Some(input) => input, }; diff --git a/dasp_graph/src/node/signal.rs b/dasp_graph/src/node/signal.rs index cd8285bc..b2a0ab8b 100644 --- a/dasp_graph/src/node/signal.rs +++ b/dasp_graph/src/node/signal.rs @@ -7,12 +7,11 @@ where F: Frame, { fn process(&mut self, _inputs: &[Input], output: &mut [Buffer]) { - let channels = std::cmp::min(F::CHANNELS, output.len()); for ix in 0..Buffer::LEN { let frame = self.next(); - for ch in 0..channels { - // Safe, as we verify the number of channels at the beginning of the function. - output[ch][ix] = unsafe { *frame.channel_unchecked(ch) }; + for (ch, out) in output.iter_mut().enumerate().take(F::CHANNELS) { + // Safe, as ch never exceeds min(F::CHANNELS, output.len()). + out[ix] = unsafe { *frame.channel_unchecked(ch) }; } } }