From 700a5f007a3d7732c1b44eb850ef37c5c1b49c1e Mon Sep 17 00:00:00 2001 From: jfinkels Date: Sat, 11 Jan 2025 11:47:23 -0500 Subject: [PATCH] tsort: use iterators to remove from vec Co-authored-by: Sylvestre Ledru --- src/uu/tsort/src/tsort.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/uu/tsort/src/tsort.rs b/src/uu/tsort/src/tsort.rs index 2f0b4c9b8..91036fe27 100644 --- a/src/uu/tsort/src/tsort.rs +++ b/src/uu/tsort/src/tsort.rs @@ -105,13 +105,10 @@ fn remove(vec: &mut Vec, x: T) -> Option where T: PartialEq, { - for i in 0..vec.len() { - if vec[i] == x { - vec.remove(i); - return Some(i); - } - } - None + vec.iter().position(|item| *item == x).map(|i| { + vec.remove(i); + i + }) } // We use String as a representation of node here