Skip to content

Commit 84c90f3

Browse files
committed
alloc: Implement rfold for VecDeque iterators
1 parent a59a25d commit 84c90f3

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/liballoc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
#![feature(generic_param_attrs)]
9999
#![feature(i128_type)]
100100
#![feature(inclusive_range)]
101+
#![feature(iter_rfold)]
101102
#![feature(lang_items)]
102103
#![feature(needs_allocator)]
103104
#![feature(nonzero)]

src/liballoc/vec_deque.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,6 +1973,14 @@ impl<'a, T> DoubleEndedIterator for Iter<'a, T> {
19731973
self.head = wrap_index(self.head.wrapping_sub(1), self.ring.len());
19741974
unsafe { Some(self.ring.get_unchecked(self.head)) }
19751975
}
1976+
1977+
fn rfold<Acc, F>(self, mut accum: Acc, mut f: F) -> Acc
1978+
where F: FnMut(Acc, Self::Item) -> Acc
1979+
{
1980+
let (front, back) = RingSlices::ring_slices(self.ring, self.head, self.tail);
1981+
accum = back.iter().rfold(accum, &mut f);
1982+
front.iter().rfold(accum, &mut f)
1983+
}
19761984
}
19771985

19781986
#[stable(feature = "rust1", since = "1.0.0")]
@@ -2058,6 +2066,14 @@ impl<'a, T> DoubleEndedIterator for IterMut<'a, T> {
20582066
Some(&mut *(elem as *mut _))
20592067
}
20602068
}
2069+
2070+
fn rfold<Acc, F>(self, mut accum: Acc, mut f: F) -> Acc
2071+
where F: FnMut(Acc, Self::Item) -> Acc
2072+
{
2073+
let (front, back) = RingSlices::ring_slices(self.ring, self.head, self.tail);
2074+
accum = back.iter_mut().rfold(accum, &mut f);
2075+
front.iter_mut().rfold(accum, &mut f)
2076+
}
20612077
}
20622078

20632079
#[stable(feature = "rust1", since = "1.0.0")]

0 commit comments

Comments
 (0)