nanvm_lib/common/
array.rs1use super::default::default;
2
3pub trait Array {
4 const SIZE: usize;
5 type Item: Default;
6 fn as_slice(&self) -> &[Self::Item];
7 fn as_mut_slice(&mut self) -> &mut [Self::Item];
8 fn new() -> Self;
11}
12
13impl<T: Default + Copy, const SIZE: usize> Array for [T; SIZE] {
14 const SIZE: usize = SIZE;
15 type Item = T;
16 fn as_slice(&self) -> &[T] {
17 self
18 }
19 fn as_mut_slice(&mut self) -> &mut [T] {
20 self
21 }
22 fn new() -> Self {
23 [default(); SIZE]
24 }
25}