orx_linked_list/iter/
doubly_iter.rs1use super::doubly_iter_ptr::DoublyIterPtr;
2use crate::Doubly;
3use core::iter::FusedIterator;
4use orx_pinned_vec::PinnedVec;
5use orx_selfref_col::{CoreCol, Node, NodePtr};
6
7pub struct DoublyIter<'a, T, P>(DoublyIterPtr<'a, T, P>)
11where
12 P: PinnedVec<Node<Doubly<T>>>;
13
14impl<'a, T, P> DoublyIter<'a, T, P>
15where
16 P: PinnedVec<Node<Doubly<T>>>,
17{
18 pub(crate) fn new(
19 col: &'a CoreCol<Doubly<T>, P>,
20 current: Option<NodePtr<Doubly<T>>>,
21 current_back: Option<NodePtr<Doubly<T>>>,
22 ) -> Self {
23 Self(DoublyIterPtr::new(col, current, current_back))
24 }
25}
26
27impl<'a, T, P> Iterator for DoublyIter<'a, T, P>
28where
29 P: PinnedVec<Node<Doubly<T>>>,
30{
31 type Item = &'a T;
32
33 #[inline(always)]
34 fn next(&mut self) -> Option<Self::Item> {
35 self.0
36 .next()
37 .map(|p| unsafe { self.0.col.data_unchecked(&p) })
38 }
39}
40
41impl<T, P> DoubleEndedIterator for DoublyIter<'_, T, P>
42where
43 P: PinnedVec<Node<Doubly<T>>>,
44{
45 #[inline(always)]
46 fn next_back(&mut self) -> Option<Self::Item> {
47 self.0
48 .next_back()
49 .map(|p| unsafe { self.0.col.data_unchecked(&p) })
50 }
51}
52
53impl<T, P> FusedIterator for DoublyIter<'_, T, P> where P: PinnedVec<Node<Doubly<T>>> {}
54
55impl<T, P> Clone for DoublyIter<'_, T, P>
56where
57 P: PinnedVec<Node<Doubly<T>>>,
58{
59 fn clone(&self) -> Self {
60 Self(self.0.clone())
61 }
62}