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
pub struct Point<T> {
index: T,
size: usize,
}
impl<T: PartialEq + Clone> Point<T> {
pub const fn new(index: T, size: usize) -> Self {
Self { index, size }
}
pub const fn is_empty(&self) -> bool {
self.len() == 0
}
pub const fn len(&self) -> usize {
self.size
}
pub fn is_full(link: &[T]) -> bool {
assert!(
link.len() >= 2,
"cannot determine link's pointless using only its identifier"
);
let a = unsafe { link.first().unwrap_unchecked() };
link.iter().skip(1).all(|b| b == a)
}
pub fn is_partial(link: &[T]) -> bool {
assert!(
link.len() >= 2,
"cannot determine link's pointless using only its identifier"
);
let a = unsafe { link.first().unwrap_unchecked() };
link.iter().skip(1).any(|b| b == a)
}
pub const fn get(&self, index: usize) -> Option<&T> {
if index < self.len() {
Some(&self.index)
} else {
None
}
}
}
impl<T: PartialEq + Copy> IntoIterator for Point<T> {
type Item = T;
type IntoIter = impl Iterator<Item = T>;
fn into_iter(self) -> Self::IntoIter {
(0..self.len()).map(move |_| self.index)
}
}