Skip to content

Commit

Permalink
feat(cordyceps): add iter::Extend for List (#232)
Browse files Browse the repository at this point in the history
This commit implements `core::iter::Extend<T::Handle>` for `List<T>`.

Closes #225
  • Loading branch information
hawkw committed Jun 19, 2022
1 parent 619565c commit a50b7c2
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion cordyceps/src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use super::Linked;
use crate::util::FmtOption;
use core::{
cell::UnsafeCell,
fmt,
fmt, iter,
marker::PhantomPinned,
mem,
pin::Pin,
Expand Down Expand Up @@ -746,6 +746,20 @@ impl<T: Linked<Links<T>> + ?Sized> List<T> {
}
}

impl<T> iter::Extend<T::Handle> for List<T>
where
T: Linked<Links<T>> + ?Sized,
{
fn extend<I: IntoIterator<Item = T::Handle>>(&mut self, iter: I) {
for item in iter {
self.push_back(item);
}
}

// TODO(eliza): when `Extend::extend_one` becomes stable, implement that
// as well, so that we can just call `push_back` without looping.
}

unsafe impl<T: Linked<Links<T>> + ?Sized> Send for List<T> where T: Send {}
unsafe impl<T: Linked<Links<T>> + ?Sized> Sync for List<T> where T: Sync {}

Expand Down

0 comments on commit a50b7c2

Please sign in to comment.