Skip to main content

wowlab_engine_domain/rotation/buffer/dense/
iter.rs

1use crate::rotation::buffer::HistorySlot;
2
3/// Iterator yielding mutable history slots without allocating a key list.
4#[derive(Debug)]
5pub struct HistoryIterMut<'a> {
6    pub(super) rest: &'a mut [u8],
7    pub(super) offsets: std::vec::IntoIter<usize>,
8    pub(super) consumed: usize,
9}
10
11impl<'a> Iterator for HistoryIterMut<'a> {
12    type Item = &'a mut HistorySlot;
13
14    #[inline]
15    fn next(&mut self) -> Option<Self::Item> {
16        let off = self.offsets.next()?;
17        let rest = std::mem::take(&mut self.rest);
18        let (_, tail) = rest.split_at_mut(off - self.consumed);
19        let (slot_bytes, tail) = tail.split_at_mut(HistorySlot::SIZE);
20
21        self.consumed = off + HistorySlot::SIZE;
22        self.rest = tail;
23
24        Some(bytemuck::from_bytes_mut::<HistorySlot>(slot_bytes))
25    }
26}
27
28impl std::iter::FusedIterator for HistoryIterMut<'_> {}