Skip to content

Commit 6c193ed

Browse files
authored
Merge pull request #802 from molarmanful/vecdeque-accumulate
feat(stream): Implement Accumulate for VecDeque
2 parents f226010 + 5db615d commit 6c193ed

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

src/stream/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ use crate::lib::std::collections::HashMap;
3333
#[cfg(feature = "std")]
3434
use crate::lib::std::collections::HashSet;
3535
#[cfg(feature = "alloc")]
36+
use crate::lib::std::collections::VecDeque;
37+
#[cfg(feature = "alloc")]
3638
use crate::lib::std::string::String;
3739
#[cfg(feature = "alloc")]
3840
use crate::lib::std::vec::Vec;
@@ -1549,6 +1551,21 @@ where
15491551
}
15501552
}
15511553

1554+
#[cfg(feature = "alloc")]
1555+
impl<'i, T: Clone> Accumulate<&'i [T]> for VecDeque<T> {
1556+
#[inline(always)]
1557+
fn initial(capacity: Option<usize>) -> Self {
1558+
match capacity {
1559+
Some(capacity) => VecDeque::with_capacity(clamp_capacity::<T>(capacity)),
1560+
None => VecDeque::new(),
1561+
}
1562+
}
1563+
#[inline(always)]
1564+
fn accumulate(&mut self, acc: &'i [T]) {
1565+
self.extend(acc.iter().cloned());
1566+
}
1567+
}
1568+
15521569
#[cfg(feature = "alloc")]
15531570
#[inline]
15541571
pub(crate) fn clamp_capacity<T>(capacity: usize) -> usize {

0 commit comments

Comments
 (0)