Skip to content

Commit b3d4898

Browse files
bors[bot]taiki-e
andauthored
Merge #657
657: impl Deref for set::Entry r=Vtec234 a=taiki-e *This originally suggested by @caelunshun in #535 (comment) cc #635 Co-authored-by: Taiki Endo <[email protected]>
2 parents f396046 + 8c91cae commit b3d4898

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

crossbeam-skiplist/src/set.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use std::borrow::Borrow;
44
use std::fmt;
55
use std::iter::FromIterator;
6+
use std::ops::Deref;
67
use std::ops::{Bound, RangeBounds};
78

89
use crate::map;
@@ -281,6 +282,14 @@ where
281282
}
282283
}
283284

285+
impl<T> Deref for Entry<'_, T> {
286+
type Target = T;
287+
288+
fn deref(&self) -> &Self::Target {
289+
self.value()
290+
}
291+
}
292+
284293
/// An owning iterator over the entries of a `SkipSet`.
285294
pub struct IntoIter<T> {
286295
inner: map::IntoIter<T, ()>,

crossbeam-skiplist/tests/set.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,27 @@ fn smoke() {
77
m.insert(5);
88
m.insert(7);
99
}
10+
11+
#[test]
12+
fn iter() {
13+
let s = SkipSet::new();
14+
for &x in &[4, 2, 12, 8, 7, 11, 5] {
15+
s.insert(x);
16+
}
17+
18+
assert_eq!(
19+
s.iter().map(|e| *e).collect::<Vec<_>>(),
20+
&[2, 4, 5, 7, 8, 11, 12]
21+
);
22+
23+
let mut it = s.iter();
24+
s.remove(&2);
25+
assert_eq!(*it.next().unwrap(), 4);
26+
s.remove(&7);
27+
assert_eq!(*it.next().unwrap(), 5);
28+
s.remove(&5);
29+
assert_eq!(*it.next().unwrap(), 8);
30+
s.remove(&12);
31+
assert_eq!(*it.next().unwrap(), 11);
32+
assert!(it.next().is_none());
33+
}

0 commit comments

Comments
 (0)