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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
use crate::{
common::*,
impls,
size::{Dyn, IntoSize, Size},
};
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
pub struct Vect<T, S>
where
S: Size,
{
pub(crate) data: Vec<T>,
pub(crate) _phantom: PhantomData<S>,
}
impl<T> Vect<T, U0> {
pub fn new() -> Self {
Self {
data: vec![],
_phantom: PhantomData,
}
}
pub fn with_capacity(capacity: usize) -> Self {
Self {
data: Vec::with_capacity(capacity),
_phantom: PhantomData,
}
}
pub fn len(&self) -> usize {
U0::USIZE
}
}
impl<T> Vect<T, Dyn> {
pub fn new() -> Self {
Self {
data: vec![],
_phantom: PhantomData,
}
}
pub fn from_vec(data: Vec<T>) -> Self {
Self {
data,
_phantom: PhantomData,
}
}
pub fn with_capacity(capacity: usize) -> Self {
Self {
data: Vec::with_capacity(capacity),
_phantom: PhantomData,
}
}
pub fn len(&self) -> usize {
self.data.len()
}
pub fn into_static<S>(self) -> Option<Vect<T, S>>
where
S: Unsigned + Size,
{
let data = self.data;
if data.len() == S::USIZE {
Some(Vect {
data,
_phantom: PhantomData,
})
} else {
None
}
}
}
impl<T, U, B> Vect<T, UInt<U, B>>
where
U: Unsigned,
B: Bit,
{
pub fn len(&self) -> usize {
UInt::<U, B>::USIZE
}
}
impl<T, S> Vect<T, S>
where
S: Size,
{
pub fn push(self, elem: T) -> impls::PushImplOp<Self, T>
where
(): impls::PushImpl<Self, T>,
{
<() as impls::PushImpl<Self, T>>::impl_push(self, elem)
}
pub fn pop(self) -> impls::PopImplOp<Self>
where
(): impls::PopImpl<Self>,
{
<() as impls::PopImpl<Self>>::impl_pop(self)
}
pub fn get<'a, I>(&'a self, index: I) -> impls::GetImplOp<'a, Self, I::Output>
where
I: IntoSize,
(): impls::GetImpl<'a, Self, I::Output>,
{
<() as impls::GetImpl<'a, Self, I::Output>>::impl_get(self, index.into_size())
}
pub fn insert<I>(self, index: I, elem: T) -> impls::InsertImplOp<Self, I::Output, T>
where
I: IntoSize,
(): impls::InsertImpl<Self, I::Output, T>,
{
<() as impls::InsertImpl<Self, I::Output, T>>::impl_insert(self, index.into_size(), elem)
}
pub fn remove<I>(self, index: I) -> impls::RemoveImplOp<Self, I::Output>
where
I: IntoSize,
(): impls::RemoveImpl<Self, I::Output>,
{
<() as impls::RemoveImpl<Self, I::Output>>::impl_remove(self, index.into_size())
}
pub fn into_dyn(self) -> Vect<T, Dyn> {
Vect {
data: self.data,
_phantom: PhantomData,
}
}
pub fn into_vec(self) -> Vec<T> {
self.data
}
}