orx_linked_list/list/slice/
list_slice.rs

1use crate::{
2    Doubly, Singly,
3    list::helper_traits::{HasCol, HasDoublyEnds, HasSinglyEnds},
4    type_aliases::{DefaultMemory, DefaultPinVec},
5    variant::ListVariant,
6};
7use orx_pinned_vec::PinnedVec;
8use orx_selfref_col::{MemoryPolicy, Node, SelfRefCol, Variant};
9
10/// A slice of a linked list.
11///
12/// Note that a list slice itself behaves pretty much like a linked list.
13/// However, it does not own the data, but provides a view on it, just as a slice of a vec.
14pub struct ListSlice<'a, V, M = DefaultMemory<V>, P = DefaultPinVec<V>>
15where
16    V: ListVariant,
17    M: MemoryPolicy<V>,
18    P: PinnedVec<Node<V>>,
19{
20    pub(crate) col: &'a SelfRefCol<V, M, P>,
21    pub(crate) ends: V::Ends,
22}
23
24impl<V, M, P> HasCol<V, M, P> for ListSlice<'_, V, M, P>
25where
26    V: ListVariant,
27    M: MemoryPolicy<V>,
28    P: PinnedVec<Node<V>>,
29{
30    #[inline(always)]
31    fn col(&self) -> &SelfRefCol<V, M, P> {
32        self.col
33    }
34}
35
36impl<T, M, P> HasSinglyEnds<T, M, P> for ListSlice<'_, Singly<T>, M, P>
37where
38    M: MemoryPolicy<Singly<T>>,
39    P: PinnedVec<Node<Singly<T>>>,
40{
41    #[inline(always)]
42    fn ends(&self) -> &<Singly<T> as Variant>::Ends {
43        &self.ends
44    }
45}
46
47impl<T, M, P> HasDoublyEnds<T, M, P> for ListSlice<'_, Doubly<T>, M, P>
48where
49    M: MemoryPolicy<Doubly<T>>,
50    P: PinnedVec<Node<Doubly<T>>>,
51{
52    #[inline(always)]
53    fn ends(&self) -> &<Doubly<T> as Variant>::Ends {
54        &self.ends
55    }
56}