Skip to content

Commit 97f74b0

Browse files
committed
Updated to fix clippy
Fixed clippy lint (added tab and spaced out `=(K,V)` => `= (K, V)`). Also made the test more explicit.
1 parent cce9a3e commit 97f74b0

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/map.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -956,8 +956,8 @@ where
956956
}
957957
}
958958
}
959-
/// Retains only the elements specified by the predicate, and returns an iterator over the
960-
/// removed items.
959+
/// Drains elements which are false under the given predicate,
960+
/// and returns an iterator over the removed items.
961961
///
962962
/// In other words, move all pairs `(k, v)` such that `f(&k,&mut v)` returns `false` out
963963
/// into another iterator.
@@ -972,7 +972,8 @@ where
972972
/// assert_eq!(drained.count(), 4);
973973
/// assert_eq!(map.len(), 4);
974974
/// ```
975-
pub fn drain_filter<'a, F>(&'a mut self, mut f: F) -> impl Iterator<Item=(K,V)> + '_
975+
#[must_use]
976+
pub fn drain_filter<'a, F>(&'a mut self, mut f: F) -> impl Iterator<Item = (K, V)> + '_
976977
where
977978
F: 'a + FnMut(&K, &mut V) -> bool,
978979
{
@@ -3526,10 +3527,12 @@ mod test_map {
35263527

35273528
#[test]
35283529
fn test_drain_filter() {
3529-
let mut map: HashMap<i32, i32> = (0..8).map(|x|(x, x*10)).collect();
3530-
let drained = map.drain_filter(|&k, _| k % 2 == 0);
3531-
assert_eq!(drained.count(), 4);
3532-
assert_eq!(map.len(), 4);
3530+
let mut map: HashMap<i32, i32> = (0..8).map(|x| (x, x * 10)).collect();
3531+
let drained = map.drain_filter(|&k, _| k % 2 == 0);
3532+
let mut out = drained.collect::<Vec<_>>();
3533+
out.sort_unstable();
3534+
assert_eq!(vec![(1, 10), (3, 30), (5, 50), (7, 70)], out);
3535+
assert_eq!(map.len(), 4);
35333536
}
35343537

35353538
#[test]

0 commit comments

Comments
 (0)