Skip to content

Commit

Permalink
Merge #657
Browse files Browse the repository at this point in the history
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 <te316e89@gmail.com>
  • Loading branch information
bors[bot] and taiki-e committed Feb 13, 2021
2 parents f396046 + 8c91cae commit b3d4898
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
9 changes: 9 additions & 0 deletions crossbeam-skiplist/src/set.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -281,6 +282,14 @@ where
}
}

impl<T> 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<T> {
inner: map::IntoIter<T, ()>,
Expand Down
24 changes: 24 additions & 0 deletions crossbeam-skiplist/tests/set.rs
Expand Up @@ -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::<Vec<_>>(),
&[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());
}

0 comments on commit b3d4898

Please sign in to comment.