Skip to content

Commit 1bb33e0

Browse files
committed
tsort: derive Default trait for Node struct
Replace custom `Node::new` function with derived `Default` implementation, which does the same thing but more concisely.
1 parent f94fd11 commit 1bb33e0

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

src/uu/tsort/src/tsort.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,20 +114,13 @@ pub fn uu_app() -> Command {
114114

115115
// We use String as a representation of node here
116116
// but using integer may improve performance.
117-
117+
#[derive(Default)]
118118
struct Node<'input> {
119119
successor_names: Vec<&'input str>,
120120
predecessor_count: usize,
121121
}
122122

123123
impl<'input> Node<'input> {
124-
fn new() -> Self {
125-
Node {
126-
successor_names: Vec::new(),
127-
predecessor_count: 0,
128-
}
129-
}
130-
131124
fn add_successor(&mut self, successor_name: &'input str) {
132125
self.successor_names.push(successor_name);
133126
}
@@ -139,7 +132,7 @@ struct Graph<'input> {
139132

140133
impl<'input> Graph<'input> {
141134
fn add_node(&mut self, name: &'input str) {
142-
self.nodes.entry(name).or_insert_with(Node::new);
135+
self.nodes.entry(name).or_default();
143136
}
144137

145138
fn add_edge(&mut self, from: &'input str, to: &'input str) {

0 commit comments

Comments
 (0)