Skip to content

Commit f9a926a

Browse files
committed
Implement RFC 839 for LinkedList
1 parent b7c5882 commit f9a926a

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/libcollections/linked_list.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,13 @@ impl<A> Extend<A> for LinkedList<A> {
871871
}
872872
}
873873

874+
#[unstable(feature = "extend_ref", reason = "recently added")]
875+
impl<'a, T: 'a + Copy> Extend<&'a T> for LinkedList<T> {
876+
fn extend<I: IntoIterator<Item=&'a T>>(&mut self, iter: I) {
877+
self.extend(iter.into_iter().cloned());
878+
}
879+
}
880+
874881
#[stable(feature = "rust1", since = "1.0.0")]
875882
impl<A: PartialEq> PartialEq for LinkedList<A> {
876883
fn eq(&self, other: &LinkedList<A>) -> bool {

src/libcollectionstest/linked_list.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,25 @@ fn test_show() {
321321
assert_eq!(format!("{:?}", list), "[\"just\", \"one\", \"test\", \"more\"]");
322322
}
323323

324+
#[test]
325+
fn test_extend_ref() {
326+
let mut a = LinkedList::new();
327+
a.push_back(1);
328+
329+
a.extend(&[2, 3, 4]);
330+
331+
assert_eq!(a.len(), 4);
332+
assert_eq!(a, list_from(&[1, 2, 3, 4]));
333+
334+
let mut b = LinkedList::new();
335+
b.push_back(5);
336+
b.push_back(6);
337+
a.extend(&b);
338+
339+
assert_eq!(a.len(), 6);
340+
assert_eq!(a, list_from(&[1, 2, 3, 4, 5, 6]));
341+
}
342+
324343
#[bench]
325344
fn bench_collect_into(b: &mut test::Bencher) {
326345
let v = &[0; 64];

0 commit comments

Comments
 (0)