Skip to content

Commit a4d396c

Browse files
committed
Impl Extend for Deque
This matches the impls for the Vec type
1 parent 9a22b83 commit a4d396c

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1414
- Added `is_full`, `recent_index`, `oldest`, and `oldest_index` to `HistoryBuffer`
1515
- Added infallible conversions from arrays to `Vec`.
1616
- Added `Vec::spare_capacity_mut`.
17+
- Added `Extend` impls for `Deque`.
1718

1819
### Changed
1920

src/deque.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,22 @@ impl<T: fmt::Debug, const N: usize> fmt::Debug for Deque<T, N> {
382382
}
383383
}
384384

385+
/// As with the standard library's `VecDeque`, items are added via `push_back`.
386+
impl<T, const N: usize> Extend<T> for Deque<T, N> {
387+
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
388+
for item in iter {
389+
self.push_back(item).ok().unwrap();
390+
}
391+
}
392+
}
393+
impl<'a, T: Copy, const N: usize> Extend<&'a T> for Deque<T, N> {
394+
fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I) {
395+
for item in iter {
396+
self.push_back(*item).ok().unwrap();
397+
}
398+
}
399+
}
400+
385401
/// An iterator that moves out of a [`Deque`].
386402
///
387403
/// This struct is created by calling the `into_iter` method.

0 commit comments

Comments
 (0)