orx_concurrent_vec/common_traits/index.rs
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::{elem::ConcurrentElement, ConcurrentSlice, ConcurrentVec};
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<'a, P, T> Index<usize> for ConcurrentSlice<'a, 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")
}
}