Skip to content

Commit 700a5f0

Browse files
jfinkelssylvestre
andauthored
tsort: use iterators to remove from vec
Co-authored-by: Sylvestre Ledru <[email protected]>
1 parent af99952 commit 700a5f0

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/uu/tsort/src/tsort.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,10 @@ fn remove<T>(vec: &mut Vec<T>, x: T) -> Option<usize>
105105
where
106106
T: PartialEq,
107107
{
108-
for i in 0..vec.len() {
109-
if vec[i] == x {
110-
vec.remove(i);
111-
return Some(i);
112-
}
113-
}
114-
None
108+
vec.iter().position(|item| *item == x).map(|i| {
109+
vec.remove(i);
110+
i
111+
})
115112
}
116113

117114
// We use String as a representation of node here

0 commit comments

Comments
 (0)