omp_gdk/types/
staticarray.rs

1use std::ops::{Index, IndexMut};
2
3#[derive(Copy, Clone, Debug)]
4#[repr(C)]
5pub struct StaticArray<T: Default + Copy, const SIZE: usize> {
6    elements: [T; SIZE],
7}
8
9impl<T: Default + Copy, const SIZE: usize> Default for StaticArray<T, SIZE> {
10    fn default() -> Self {
11        Self {
12            elements: [T::default(); SIZE],
13        }
14    }
15}
16
17impl<T: Default + Copy, const SIZE: usize> Index<usize> for StaticArray<T, SIZE> {
18    type Output = T;
19    fn index(&self, i: usize) -> &T {
20        &self.elements[i]
21    }
22}
23
24impl<T: Default + Copy, const SIZE: usize> IndexMut<usize> for StaticArray<T, SIZE> {
25    fn index_mut(&mut self, i: usize) -> &mut T {
26        &mut self.elements[i]
27    }
28}