Skip to content

Fix several clippy lints in dasp_graph. #189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dasp_graph/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl fmt::Debug for Buffer {

impl PartialEq for Buffer {
fn eq(&self, other: &Self) -> bool {
&self[..] == &other[..]
self[..] == other[..]
}
}

Expand Down
20 changes: 8 additions & 12 deletions dasp_graph/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<Item = G::NodeId>
pub fn sources<G>(g: &G) -> impl '_ + Iterator<Item = G::NodeId>
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<Item = G::NodeId>
pub fn sinks<G>(g: &G) -> impl '_ + Iterator<Item = G::NodeId>
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())
}
12 changes: 6 additions & 6 deletions dasp_graph/src/node/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ where
}
}

impl Into<Box<dyn Node>> for BoxedNode {
fn into(self) -> Box<dyn Node> {
self.0
impl From<BoxedNode> for Box<dyn Node> {
fn from(val: BoxedNode) -> Self {
val.0
}
}

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

Expand Down
2 changes: 1 addition & 1 deletion dasp_graph/src/node/delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
2 changes: 1 addition & 1 deletion dasp_graph/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl fmt::Debug for Input {
}
}

impl<'a, T> Node for &'a mut T
impl<T> Node for &mut T
where
T: Node + ?Sized,
{
Expand Down
2 changes: 1 addition & 1 deletion dasp_graph/src/node/pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
7 changes: 3 additions & 4 deletions dasp_graph/src/node/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ where
F: Frame<Sample = f32>,
{
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) };
}
}
}
Expand Down
Loading