1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use crate::{
    list::helper_traits::{HasCol, HasDoublyEnds, HasSinglyEnds},
    type_aliases::{DefaultMemory, PinVec},
    variant::ListVariant,
    Doubly, Singly,
};
use orx_selfref_col::{MemoryPolicy, SelfRefCol, Variant};

/// A slice of a linked list.
///
/// Note that a list slice itself behaves pretty much like a linked list.
/// However, it does not own the data, but provides a view on it, just as a slice of a vec.
pub struct ListSlice<'a, V, M = DefaultMemory<V>>
where
    V: ListVariant,
    M: MemoryPolicy<V>,
{
    pub(crate) col: &'a SelfRefCol<V, M, PinVec<V>>,
    pub(crate) ends: V::Ends,
}

impl<'a, V, M> HasCol<V, M> for ListSlice<'a, V, M>
where
    V: ListVariant,
    M: MemoryPolicy<V>,
{
    #[inline(always)]
    fn col(&self) -> &SelfRefCol<V, M, PinVec<V>> {
        self.col
    }
}

impl<'a, T, M> HasSinglyEnds<T, M> for ListSlice<'a, Singly<T>, M>
where
    M: MemoryPolicy<Singly<T>>,
{
    #[inline(always)]
    fn ends(&self) -> &<Singly<T> as Variant>::Ends {
        &self.ends
    }
}

impl<'a, T, M> HasDoublyEnds<T, M> for ListSlice<'a, Doubly<T>, M>
where
    M: MemoryPolicy<Doubly<T>>,
{
    #[inline(always)]
    fn ends(&self) -> &<Doubly<T> as Variant>::Ends {
        &self.ends
    }
}