Documentation
use super::core::next_index;

pub struct ShapeIterator {
    pub(super) shape: Vec<usize>,
    pub(super) index: Vec<usize>,
    pub(super) end: bool,
}

impl ShapeIterator {
    pub fn new(shape: &Vec<usize>) -> Self {
        ShapeIterator {
            shape: shape.clone(),
            index: vec![0; shape.len()],
            end: false,
        }
    }
}

impl Iterator for ShapeIterator {
    type Item = Vec<usize>;

    fn next(&mut self) -> Option<Self::Item> {
        if self.end {
            return None;
        }

        let out = self.index.clone();
        self.end = next_index(&self.shape, &mut self.index);

        Some(out)
    }
}