|
|
@ -141,23 +141,27 @@ impl<'a, T> Iterator for Iter<'a, T> {
|
|
|
|
type Item = &'a T;
|
|
|
|
type Item = &'a T;
|
|
|
|
|
|
|
|
|
|
|
|
fn next(&mut self) -> Option<Self::Item> {
|
|
|
|
fn next(&mut self) -> Option<Self::Item> {
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
self.next.map(|node| {
|
|
|
|
self.next.map(|node| {
|
|
|
|
self.next = node.next.as_deref();
|
|
|
|
self.next = node.next.as_ref();
|
|
|
|
&node.elem
|
|
|
|
&node.elem
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl<'a, T> Iterator for IterMut<'a, T> {
|
|
|
|
impl<'a, T> Iterator for IterMut<'a, T> {
|
|
|
|
type Item = &'a mut T;
|
|
|
|
type Item = &'a mut T;
|
|
|
|
|
|
|
|
|
|
|
|
fn next(&mut self) -> Option<Self::Item> {
|
|
|
|
fn next(&mut self) -> Option<Self::Item> {
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
self.next.take().map(|node| {
|
|
|
|
self.next.take().map(|node| {
|
|
|
|
self.next = node.next.as_deref_mut();
|
|
|
|
self.next = node.next.as_mut();
|
|
|
|
&mut node.elem
|
|
|
|
&mut node.elem
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
验证下测试用例:
|
|
|
|
验证下测试用例:
|
|
|
|