Skip to content

Commit

Permalink
feat(cordyceps): impl IntoIterator for List (#208)
Browse files Browse the repository at this point in the history
Signed-off-by: Eliza Weisman <[email protected]>
  • Loading branch information
hawkw committed Jun 7, 2022
1 parent f5d6ea1 commit 1e95127
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions cordyceps/src/list.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! An intrusive doubly-linked list.
//!
//! See the [`List`] type for details.
use super::Linked;
use crate::util::FmtOption;
use core::{
Expand Down Expand Up @@ -557,6 +558,26 @@ impl<T: Linked<Links<T>> + ?Sized> fmt::Debug for List<T> {
}
}

impl<'list, T: Linked<Links<T>> + ?Sized> IntoIterator for &'list List<T> {
type Item = &'list T;
type IntoIter = Iter<'list, T>;

#[inline]
fn into_iter(self) -> Self::IntoIter {
self.iter()
}
}

impl<'list, T: Linked<Links<T>> + ?Sized> IntoIterator for &'list mut List<T> {
type Item = &'list mut T;
type IntoIter = IterMut<'list, T>;

#[inline]
fn into_iter(self) -> Self::IntoIter {
self.iter_mut()
}
}

impl<T: Linked<Links<T>> + ?Sized> Drop for List<T> {
fn drop(&mut self) {
while let Some(node) = self.pop_front() {
Expand Down Expand Up @@ -748,8 +769,6 @@ impl<'a, T: Linked<Links<T>> + ?Sized> Cursor<'a, T> {
}
}

// TODO(eliza): next_back

// === impl Iter ====

impl<'list, T: Linked<Links<T>> + ?Sized> Iterator for Iter<'list, T> {
Expand Down

0 comments on commit 1e95127

Please sign in to comment.