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
use crate::Value;
use std::ops::Index;
use std::slice::SliceIndex;
pub trait Array: Index<usize> + Sync + Send + Clone {
type Element: Value;
#[must_use]
fn get<I>(&self, i: I) -> Option<&<I as SliceIndex<[Self::Element]>>::Output>
where
I: SliceIndex<[Self::Element]>;
#[must_use]
fn get_mut(&mut self, i: usize) -> Option<&mut Self::Element>;
#[must_use]
fn pop(&mut self) -> Option<Self::Element>;
fn push(&mut self, e: Self::Element);
#[must_use]
fn iter<'i>(&'i self) -> Box<dyn Iterator<Item = &Self::Element> + 'i>;
#[must_use]
fn len(&self) -> usize;
#[must_use]
fn is_empty(&self) -> bool {
self.len() == 0
}
}
impl<T> Array for Vec<T>
where
T: Value + Sync + Send + Clone,
{
type Element = T;
#[inline]
fn get<I>(&self, i: I) -> Option<&<I as SliceIndex<[T]>>::Output>
where
I: SliceIndex<[T]>,
{
<[T]>::get(self, i)
}
#[inline]
fn get_mut(&mut self, i: usize) -> Option<&mut T> {
<[T]>::get_mut(self, i)
}
#[inline]
fn pop(&mut self) -> Option<T> {
Vec::pop(self)
}
#[inline]
fn push(&mut self, e: T) {
Vec::push(self, e);
}
fn iter<'i>(&'i self) -> Box<dyn Iterator<Item = &T> + 'i> {
Box::new(<[T]>::iter(self))
}
#[inline]
fn len(&self) -> usize {
self.len()
}
}
#[cfg(feature = "c-abi")]
impl<T> Array for abi_stable::std_types::RVec<T>
where
T: Value + Sync + Send + Clone,
{
type Element = T;
#[inline]
fn get<I>(&self, i: I) -> Option<&<I as SliceIndex<[T]>>::Output>
where
I: SliceIndex<[T]>,
{
<[T]>::get(self, i)
}
#[inline]
fn get_mut(&mut self, i: usize) -> Option<&mut T> {
<[T]>::get_mut(self, i)
}
#[inline]
fn pop(&mut self) -> Option<T> {
abi_stable::std_types::RVec::pop(self)
}
#[inline]
fn push(&mut self, e: T) {
abi_stable::std_types::RVec::push(self, e)
}
fn iter<'i>(&'i self) -> Box<dyn Iterator<Item = &T> + 'i> {
Box::new(<[T]>::iter(self))
}
#[inline]
fn len(&self) -> usize {
self.len()
}
}