1pub use crate::{keyboard::Button, ButtonAbstraction};
2
3pub struct Shape(Vec<usize>);
4
5impl From<(usize, usize)> for Shape {
6 fn from(d12: (usize, usize)) -> Self {
7 Self(vec![d12.0, d12.1])
8 }
9}
10
11impl Shape {
12 pub fn dims(&self) -> &[usize] {
13 &self.0
14 }
15}
16
17pub trait NdArray<T> {
18 fn shape(&self) -> Shape;
19
20 fn slice(&self) -> Vec<Vec<&Button<T>>>;
21}
22
23impl<T: serde::Serialize, const N: usize, const M: usize> NdArray<T> for &[[Button<T>; N]; M] {
24 fn shape(&self) -> Shape {
25 Shape::from((M, N))
26 }
27
28 fn slice(&self) -> Vec<Vec<&Button<T>>> {
29 self.iter().map(|row| row.iter().collect()).collect()
30 }
31}
32
33impl std::fmt::Debug for Shape {
34 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35 write!(f, "{:?}", &self.dims())
36 }
37}