use std::fmt;
#[derive(Debug)]
pub struct ShapeError<'s, T, const N: usize> {
slice: &'s [T],
shape: [usize; N] }
impl<'s, T, const N: usize> fmt::Display for ShapeError<'s, T, N> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"Constructing an NdSlice of shape: {:?} would need a slice of length {}, but a slice of length {} was provided",
self.shape,
self.shape.iter().fold(1, |acc, &x| acc * x),
self.slice.len()
)
}
}
impl<'s, T, const N: usize> ShapeError<'s, T, N> {
pub fn new(slice: &'s [T], shape: [usize; N]) -> Self {
Self {
slice,
shape
}
}
}