vitaminc_protected/slice_index.rs
1use crate::Protected;
2use std::ops::{Index, IndexMut};
3
4/// Allows the use a of a Paranoid usize to index an array.
5impl<const N: usize, T> Index<Protected<usize>> for [T; N] {
6 type Output = T;
7
8 fn index(&self, index: Protected<usize>) -> &Self::Output {
9 &self[index.0]
10 }
11}
12
13impl<const N: usize, T> IndexMut<Protected<usize>> for [T; N] {
14 fn index_mut(&mut self, index: Protected<usize>) -> &mut Self::Output {
15 &mut self[index.0]
16 }
17}