orx_concurrent_vec/common_traits/
index.rs

1use crate::{ConcurrentSlice, ConcurrentVec, elem::ConcurrentElement};
2use core::ops::Index;
3use orx_pinned_vec::IntoConcurrentPinnedVec;
4
5// ConcurrentVec
6
7impl<P, T> Index<usize> for ConcurrentVec<T, P>
8where
9    P: IntoConcurrentPinnedVec<ConcurrentElement<T>>,
10{
11    type Output = ConcurrentElement<T>;
12
13    /// Returns a reference to the concurrent element at the i-th position of the vec.
14    ///
15    /// Note that `vec[i]` is a shorthand for `vec.get(i).unwrap()`.
16    ///
17    /// # Panics
18    ///
19    /// Panics if i is out of bounds.
20    fn index(&self, i: usize) -> &Self::Output {
21        self.get(i).expect("out-of-bounds")
22    }
23}
24
25// ConcurrentSlice
26
27impl<P, T> Index<usize> for ConcurrentSlice<'_, T, P>
28where
29    P: IntoConcurrentPinnedVec<ConcurrentElement<T>>,
30{
31    type Output = ConcurrentElement<T>;
32
33    /// Returns a reference to the concurrent element at the i-th position of the slice.
34    ///
35    /// Note that `slice[i]` is a shorthand for `slice.get(i).unwrap()`.
36    ///
37    /// # Panics
38    ///
39    /// Panics if i is out of bounds.
40    fn index(&self, i: usize) -> &Self::Output {
41        self.get(i).expect("out-of-bounds")
42    }
43}