Skip to content

Commit 7fc1cdf

Browse files
committed
feat: use PhantomData for the lifetime marker in Iter and IterMut
1 parent 2d7786e commit 7fc1cdf

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/linked_list.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Provide the intrusive LinkedList
2-
#![allow(dead_code)]
32
3+
use core::marker::PhantomData;
44
use core::{fmt, ptr};
55

66
/// An intrusive linked list
@@ -52,7 +52,7 @@ impl LinkedList {
5252
pub fn iter(&self) -> Iter {
5353
Iter {
5454
curr: self.head,
55-
list: self,
55+
list: PhantomData,
5656
}
5757
}
5858

@@ -61,7 +61,7 @@ impl LinkedList {
6161
IterMut {
6262
prev: &mut self.head as *mut *mut usize as *mut usize,
6363
curr: self.head,
64-
list: self,
64+
list: PhantomData,
6565
}
6666
}
6767
}
@@ -75,7 +75,7 @@ impl fmt::Debug for LinkedList {
7575
/// An iterator over the linked list
7676
pub struct Iter<'a> {
7777
curr: *mut usize,
78-
list: &'a LinkedList,
78+
list: PhantomData<&'a LinkedList>,
7979
}
8080

8181
impl<'a> Iterator for Iter<'a> {
@@ -117,7 +117,7 @@ impl ListNode {
117117

118118
/// A mutable iterator over the linked list
119119
pub struct IterMut<'a> {
120-
list: &'a mut LinkedList,
120+
list: PhantomData<&'a mut LinkedList>,
121121
prev: *mut usize,
122122
curr: *mut usize,
123123
}

0 commit comments

Comments
 (0)