-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.rs
More file actions
43 lines (37 loc) · 1.14 KB
/
index.rs
File metadata and controls
43 lines (37 loc) · 1.14 KB
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
use crate::{ConcurrentSlice, ConcurrentVec, elem::ConcurrentElement};
use core::ops::Index;
use orx_pinned_vec::IntoConcurrentPinnedVec;
// ConcurrentVec
impl<P, T> Index<usize> for ConcurrentVec<T, P>
where
P: IntoConcurrentPinnedVec<ConcurrentElement<T>>,
{
type Output = ConcurrentElement<T>;
/// Returns a reference to the concurrent element at the i-th position of the vec.
///
/// Note that `vec[i]` is a shorthand for `vec.get(i).unwrap()`.
///
/// # Panics
///
/// Panics if i is out of bounds.
fn index(&self, i: usize) -> &Self::Output {
self.get(i).expect("out-of-bounds")
}
}
// ConcurrentSlice
impl<P, T> Index<usize> for ConcurrentSlice<'_, T, P>
where
P: IntoConcurrentPinnedVec<ConcurrentElement<T>>,
{
type Output = ConcurrentElement<T>;
/// Returns a reference to the concurrent element at the i-th position of the slice.
///
/// Note that `slice[i]` is a shorthand for `slice.get(i).unwrap()`.
///
/// # Panics
///
/// Panics if i is out of bounds.
fn index(&self, i: usize) -> &Self::Output {
self.get(i).expect("out-of-bounds")
}
}