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
use crate::memory::{DoublyReclaimer, SinglyReclaimer};
use core::marker::PhantomData;
use orx_selfref_col::{MemoryReclaimer, RefsArray, RefsNone, RefsSingle, Variant};

pub trait ListVariant: Variant {
    type Reclaimer: MemoryReclaimer<Self>;
}

/// A self referential collection variant representing a singly linked list
/// where nodes hold a reference to the next element, but not to the previous.
pub struct Singly<T> {
    p: PhantomData<T>,
}

impl<T> Variant for Singly<T> {
    type Item = T;

    type Prev = RefsNone;

    type Next = RefsSingle<Self>;

    type Ends = RefsSingle<Self>;
}

impl<T> ListVariant for Singly<T> {
    type Reclaimer = SinglyReclaimer;
}

/// A self referential collection variant representing a doubly linked list
/// where nodes hold a reference to the next element, and a reference to the previous.
pub struct Doubly<T> {
    p: PhantomData<T>,
}

impl<T> Variant for Doubly<T> {
    type Item = T;

    type Prev = RefsSingle<Self>;

    type Next = RefsSingle<Self>;

    type Ends = RefsArray<2, Self>;
}

impl<T> ListVariant for Doubly<T> {
    type Reclaimer = DoublyReclaimer;
}