diff --git a/crossbeam-skiplist/src/set.rs b/crossbeam-skiplist/src/set.rs index b007d2a88..7ffe477ea 100644 --- a/crossbeam-skiplist/src/set.rs +++ b/crossbeam-skiplist/src/set.rs @@ -3,6 +3,7 @@ use std::borrow::Borrow; use std::fmt; use std::iter::FromIterator; +use std::ops::Deref; use std::ops::{Bound, RangeBounds}; use crate::map; @@ -281,6 +282,14 @@ where } } +impl Deref for Entry<'_, T> { + type Target = T; + + fn deref(&self) -> &Self::Target { + self.value() + } +} + /// An owning iterator over the entries of a `SkipSet`. pub struct IntoIter { inner: map::IntoIter, diff --git a/crossbeam-skiplist/tests/set.rs b/crossbeam-skiplist/tests/set.rs index f905fea19..8274069fa 100644 --- a/crossbeam-skiplist/tests/set.rs +++ b/crossbeam-skiplist/tests/set.rs @@ -7,3 +7,27 @@ fn smoke() { m.insert(5); m.insert(7); } + +#[test] +fn iter() { + let s = SkipSet::new(); + for &x in &[4, 2, 12, 8, 7, 11, 5] { + s.insert(x); + } + + assert_eq!( + s.iter().map(|e| *e).collect::>(), + &[2, 4, 5, 7, 8, 11, 12] + ); + + let mut it = s.iter(); + s.remove(&2); + assert_eq!(*it.next().unwrap(), 4); + s.remove(&7); + assert_eq!(*it.next().unwrap(), 5); + s.remove(&5); + assert_eq!(*it.next().unwrap(), 8); + s.remove(&12); + assert_eq!(*it.next().unwrap(), 11); + assert!(it.next().is_none()); +}