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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
pub trait Index {
    type Index;
}

pub trait Pop<T> {
    fn pop(&mut self) -> Option<&T>;
    unsafe fn pop_unchecked(&mut self) -> &T;

    fn pop_mut(&mut self) -> Option<&mut T>;
    unsafe fn pop_unchecked_mut(&mut self) -> &mut T;
}

pub trait Get<T>: Index {
    fn get(&self, index: Self::Index) -> Option<&T>;
    fn get_mut(&mut self, index: Self::Index) -> Option<&mut T>;
}

pub trait GetUnchecked<T>: Index {
    unsafe fn get_unchecked(&self, index: Self::Index) -> &T;
    unsafe fn get_unchecked_mut(&mut self, index: Self::Index) -> &mut T;
}

pub trait Push<T> {
    fn push(&mut self, value: T) -> Result<(), T>;
    unsafe fn push_unchecked(&mut self, value: T);
}

pub trait Remove: Index {
    fn remove(&mut self, index: Self::Index) -> bool;
}

pub trait RemoveUnchecked: Index {
    unsafe fn remove_unchecked(&mut self, index: Self::Index);
}

pub trait Cap {
    type Cap;

    fn capacity(&self) -> Self::Cap;
}

pub trait CursorRead<T> {
    fn read(&mut self) -> Option<&T>;
    unsafe fn read_unchecked(&mut self) -> &T;
}

pub trait CursorReadTransmute {
    fn read_transmute<T>(&mut self) -> Option<&T>;
    unsafe fn read_transmute_unchecked<T>(&mut self) -> &T;
}

pub trait Clear {
    fn clear(&mut self);
}

pub trait GetTransmute: Index {
    fn get_transmute<V>(&self, index: Self::Index) -> Option<&V>;
    fn get_transmute_mut<V>(&mut self, index: Self::Index) -> Option<&mut V>;
}

pub trait GetTransmuteUnchecked: Index {
    unsafe fn get_transmute_unchecked<V>(&self, index: Self::Index) -> &V;
    unsafe fn get_transmute_mut_unchecked<V>(&mut self, index: Self::Index) -> &mut V;
}

pub trait PushTransmute {
    fn push_transmute<V>(&mut self, value: V) -> Result<(), ()>;
}

pub trait PushTransmuteUnchecked<V> {
    unsafe fn push_transmute_unchecked(&mut self, value: V);
}

pub trait SetTransmute {
    fn set_transmute<V>(&mut self, index: usize, value: V) -> Result<(), ()>;
    unsafe fn set_transmute_unchecked<V>(&mut self, index: usize, value: V);
}