Skip to content

Commit 567f1ae

Browse files
authored
Fix several clippy lints in dasp_graph. (#189)
Co-authored-by: Chloe Brett <chloebrett@users.noreply.github.com>
1 parent a1e0fed commit 567f1ae

File tree

7 files changed

+21
-26
lines changed

7 files changed

+21
-26
lines changed

dasp_graph/src/buffer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl fmt::Debug for Buffer {
4141

4242
impl PartialEq for Buffer {
4343
fn eq(&self, other: &Self) -> bool {
44-
&self[..] == &other[..]
44+
self[..] == other[..]
4545
}
4646
}
4747

dasp_graph/src/lib.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,10 @@ where
215215
where
216216
G::Map: Default,
217217
{
218-
let mut dfs_post_order = DfsPostOrder::default();
219-
dfs_post_order.stack = Vec::with_capacity(max_nodes);
218+
let dfs_post_order = DfsPostOrder {
219+
stack: Vec::with_capacity(max_nodes),
220+
..Default::default()
221+
};
220222
let inputs = Vec::with_capacity(max_nodes);
221223
Self {
222224
dfs_post_order,
@@ -346,29 +348,23 @@ where
346348
/// Produce an iterator yielding IDs for all **source** nodes within the graph.
347349
///
348350
/// A node is considered to be a source node if it has no incoming edges.
349-
pub fn sources<'a, G>(g: &'a G) -> impl 'a + Iterator<Item = G::NodeId>
351+
pub fn sources<G>(g: &G) -> impl '_ + Iterator<Item = G::NodeId>
350352
where
351353
G: IntoNeighborsDirected + NodeCount + NodeIndexable,
352354
{
353355
(0..g.node_count())
354356
.map(move |ix| g.from_index(ix))
355-
.filter_map(move |id| match g.neighbors_directed(id, Incoming).next() {
356-
None => Some(id),
357-
_ => None,
358-
})
357+
.filter(move |id| g.neighbors_directed(*id, Incoming).next().is_none())
359358
}
360359

361360
/// Produce an iterator yielding IDs for all **sink** nodes within the graph.
362361
///
363362
/// A node is considered to be a **sink** node if it has no outgoing edges.
364-
pub fn sinks<'a, G>(g: &'a G) -> impl 'a + Iterator<Item = G::NodeId>
363+
pub fn sinks<G>(g: &G) -> impl '_ + Iterator<Item = G::NodeId>
365364
where
366365
G: IntoNeighborsDirected + NodeCount + NodeIndexable,
367366
{
368367
(0..g.node_count())
369368
.map(move |ix| g.from_index(ix))
370-
.filter_map(move |id| match g.neighbors_directed(id, Outgoing).next() {
371-
None => Some(id),
372-
_ => None,
373-
})
369+
.filter(move |id| g.neighbors_directed(*id, Outgoing).next().is_none())
374370
}

dasp_graph/src/node/boxed.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ where
7272
}
7373
}
7474

75-
impl Into<Box<dyn Node>> for BoxedNode {
76-
fn into(self) -> Box<dyn Node> {
77-
self.0
75+
impl From<BoxedNode> for Box<dyn Node> {
76+
fn from(val: BoxedNode) -> Self {
77+
val.0
7878
}
7979
}
8080

81-
impl Into<Box<dyn Node + Send>> for BoxedNodeSend {
82-
fn into(self) -> Box<dyn Node + Send> {
83-
self.0
81+
impl From<BoxedNodeSend> for Box<dyn Node + Send> {
82+
fn from(val: BoxedNodeSend) -> Self {
83+
val.0
8484
}
8585
}
8686

dasp_graph/src/node/delay.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ where
1515
{
1616
fn process(&mut self, inputs: &[Input], output: &mut [Buffer]) {
1717
// Retrieve the single input, ignore any others.
18-
let input = match inputs.get(0) {
18+
let input = match inputs.first() {
1919
Some(input) => input,
2020
None => return,
2121
};

dasp_graph/src/node/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl fmt::Debug for Input {
126126
}
127127
}
128128

129-
impl<'a, T> Node for &'a mut T
129+
impl<T> Node for &mut T
130130
where
131131
T: Node + ?Sized,
132132
{

dasp_graph/src/node/pass.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub struct Pass;
1212

1313
impl Node for Pass {
1414
fn process(&mut self, inputs: &[Input], output: &mut [Buffer]) {
15-
let input = match inputs.get(0) {
15+
let input = match inputs.first() {
1616
None => return,
1717
Some(input) => input,
1818
};

dasp_graph/src/node/signal.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ where
77
F: Frame<Sample = f32>,
88
{
99
fn process(&mut self, _inputs: &[Input], output: &mut [Buffer]) {
10-
let channels = std::cmp::min(F::CHANNELS, output.len());
1110
for ix in 0..Buffer::LEN {
1211
let frame = self.next();
13-
for ch in 0..channels {
14-
// Safe, as we verify the number of channels at the beginning of the function.
15-
output[ch][ix] = unsafe { *frame.channel_unchecked(ch) };
12+
for (ch, out) in output.iter_mut().enumerate().take(F::CHANNELS) {
13+
// Safe, as ch never exceeds min(F::CHANNELS, output.len()).
14+
out[ix] = unsafe { *frame.channel_unchecked(ch) };
1615
}
1716
}
1817
}

0 commit comments

Comments
 (0)