use std::num::NonZeroUsize;
use crate::{usage_types::full_shape::FullShape, VectorGrid};
impl<ItemType> VectorGrid<ItemType> {
pub fn from_vector(defined_shape: Vec<usize>, items: Vec<ItemType>) -> Self {
Self {
defined_shape: defined_shape.iter().map(|dimension| {
NonZeroUsize::new(*dimension).expect("VectorGrid constructed in from_vector() has a dimension of size 0")
}).collect(),
items
}
}
}
impl<ItemType: Default + Clone> VectorGrid<ItemType> {
pub fn from_2d_array<const WIDTH: usize>(array: &[[ItemType; WIDTH]]) -> Self {
Self {
defined_shape: vec![
NonZeroUsize::new(WIDTH).expect("VectorGrid constructed in from_2d_array() has a width of 0"),
],
items: array.concat()
}
}
pub fn new_fill(shape: impl Into<FullShape>) -> Self {
let shape = shape.into();
Self { defined_shape: shape.defined, items: vec![ItemType::default(); shape.total_length] }
}
}