Skip to content

Commit

Permalink
feat: use PhantomData for the lifetime marker in Iter and IterMut
Browse files Browse the repository at this point in the history
  • Loading branch information
tsemo4917 committed Sep 19, 2023
1 parent 2d7786e commit 7fc1cdf
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/linked_list.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Provide the intrusive LinkedList
#![allow(dead_code)]

use core::marker::PhantomData;
use core::{fmt, ptr};

/// An intrusive linked list
Expand Down Expand Up @@ -52,7 +52,7 @@ impl LinkedList {
pub fn iter(&self) -> Iter {
Iter {
curr: self.head,
list: self,
list: PhantomData,
}
}

Expand All @@ -61,7 +61,7 @@ impl LinkedList {
IterMut {
prev: &mut self.head as *mut *mut usize as *mut usize,
curr: self.head,
list: self,
list: PhantomData,
}
}
}
Expand All @@ -75,7 +75,7 @@ impl fmt::Debug for LinkedList {
/// An iterator over the linked list
pub struct Iter<'a> {
curr: *mut usize,
list: &'a LinkedList,
list: PhantomData<&'a LinkedList>,
}

impl<'a> Iterator for Iter<'a> {
Expand Down Expand Up @@ -117,7 +117,7 @@ impl ListNode {

/// A mutable iterator over the linked list
pub struct IterMut<'a> {
list: &'a mut LinkedList,
list: PhantomData<&'a mut LinkedList>,
prev: *mut usize,
curr: *mut usize,
}
Expand Down

0 comments on commit 7fc1cdf

Please sign in to comment.