1use std::fmt;
4
5#[derive(Debug)]
7pub struct ShapeError<'s, T, const N: usize> {
8 slice: &'s [T],
9 shape: [usize; N] }
11
12impl<'s, T, const N: usize> fmt::Display for ShapeError<'s, T, N> {
13 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
14 write!(
15 f,
16 "Constructing an NdSlice of shape: {:?} would need a slice of length {}, but a slice of length {} was provided",
17 self.shape,
18 self.shape.iter().fold(1, |acc, &x| acc * x),
19 self.slice.len()
20 )
21 }
22}
23
24impl<'s, T, const N: usize> ShapeError<'s, T, N> {
25 pub fn new(slice: &'s [T], shape: [usize; N]) -> Self {
27 Self {
28 slice,
29 shape
30 }
31 }
32}