Skip to content

Commit 9b69b10

Browse files
committed
Implement RFC 839 for EnumSet
1 parent f9a926a commit 9b69b10

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/libcollections/enum_set.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,10 @@ impl<E:CLike> Extend<E> for EnumSet<E> {
288288
}
289289
}
290290
}
291+
292+
#[unstable(feature = "extend_ref", reason = "recently added")]
293+
impl<'a, E: 'a + CLike + Copy> Extend<&'a E> for EnumSet<E> {
294+
fn extend<I: IntoIterator<Item=&'a E>>(&mut self, iter: I) {
295+
self.extend(iter.into_iter().cloned());
296+
}
297+
}

src/libcollectionstest/enum_set.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,3 +242,25 @@ fn test_overflow() {
242242
let mut set = EnumSet::new();
243243
set.insert(Bar::V64);
244244
}
245+
246+
#[test]
247+
fn test_extend_ref() {
248+
let mut a = EnumSet::new();
249+
a.insert(A);
250+
251+
a.extend(&[A, C]);
252+
253+
assert_eq!(a.len(), 2);
254+
assert!(a.contains(&A));
255+
assert!(a.contains(&C));
256+
257+
let mut b = EnumSet::new();
258+
b.insert(B);
259+
260+
a.extend(&b);
261+
262+
assert_eq!(a.len(), 3);
263+
assert!(a.contains(&A));
264+
assert!(a.contains(&B));
265+
assert!(a.contains(&C));
266+
}

0 commit comments

Comments
 (0)