Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions cordyceps/src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ pub struct Iter<'list, T: Linked<Links<T>> + ?Sized> {
/// the returned `NonNull<T>` nodes. See [`List::iter_raw()`] for
/// more details on safety invariants.
pub struct IterRaw<'list, T: Linked<Links<T>> + ?Sized> {
_list: &'list List<T>,
_list: &'list mut List<T>,

/// The current node when iterating head -> tail.
curr: Link<T>,
Expand Down Expand Up @@ -963,10 +963,10 @@ impl<T: Linked<Links<T>> + ?Sized> List<T> {
#[must_use]
pub fn iter_raw(&mut self) -> IterRaw<'_, T> {
IterRaw {
_list: self,
len: self.len(),
curr: self.head,
curr_back: self.tail,
len: self.len(),
_list: self,
}
}

Expand Down Expand Up @@ -1451,7 +1451,13 @@ impl<T: Linked<Links<T>> + ?Sized> DoubleEndedIterator for IterMut<'_, T> {

impl<T: Linked<Links<T>> + ?Sized> iter::FusedIterator for IterMut<'_, T> {}

// === impl RawIter ====
// === impl IterRaw ====

/// ## SAFETY
///
/// IterRaw contains an exclusive reference to the given List, and objects
/// within the list are pinned. Therefore, `Send`-ing the iterator is sound.
unsafe impl<T: Linked<Links<T>> + ?Sized> Send for IterRaw<'_, T> {}

impl<T: Linked<Links<T>> + ?Sized> Iterator for IterRaw<'_, T> {
type Item = NonNull<T>;
Expand Down Expand Up @@ -1496,7 +1502,7 @@ impl<T: Linked<Links<T>> + ?Sized> DoubleEndedIterator for IterRaw<'_, T> {
let curr = self.curr_back.take()?;
self.len -= 1;
unsafe {
// safety: it is safe for us to borrow `curr`, because the iterator
// safety: it is safe for us to borrow `curr_back`, because the iterator
// borrows the `List`, ensuring that the list will not be dropped
// while the iterator exists. the returned item will not outlive the
// iterator.
Expand Down
5 changes: 5 additions & 0 deletions cordyceps/src/list/tests/iter_raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,8 @@ fn smoke() {

drop(list);
}

#[test]
fn assert_send() {
crate::util::assert_send::<IterRaw<'_, OwnedEntryHeader>>();
}
3 changes: 3 additions & 0 deletions cordyceps/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,6 @@ impl<T: fmt::Display> fmt::Display for FmtOption<'_, T> {

#[cfg(test)]
pub(crate) fn assert_send_sync<T: Send + Sync>() {}

#[cfg(test)]
pub(crate) fn assert_send<T: Send>() {}
Loading