diff --git a/src/collections/scoped_buffer.rs b/src/collections/scoped_buffer.rs index 4827b030ab01d643a3d8d98e4b2d38894fdbec09..0d5865bd6d7014a443f35c90c53f082ddd838ef8 100644 --- a/src/collections/scoped_buffer.rs +++ b/src/collections/scoped_buffer.rs @@ -26,7 +26,7 @@ pub(crate) struct ScopedSection { } impl ScopedBuffer { - pub(crate) fn new_reserved(capacity: usize) -> Self { + pub(crate) fn with_capacity(capacity: usize) -> Self { Self { inner: Vec::with_capacity(capacity) } } @@ -106,6 +106,16 @@ impl ScopedSection { } } +impl ScopedSection { + pub(crate) fn iter_copied(&self) -> ScopedIter { + return ScopedIter{ + inner: self.inner, + cur_index: self.start_size, + last_index: unsafe{ (*self.inner).len() as u32 }, + } + } +} + impl std::ops::Index for ScopedSection { type Output = T; @@ -122,4 +132,25 @@ impl Drop for ScopedSection { #[cfg(debug_assertions)] debug_assert_eq!(vec.len(), self.cur_size as usize); vec.truncate(self.start_size as usize); } +} + +pub(crate) struct ScopedIter { + inner: *mut Vec, + cur_index: u32, + last_index: u32, +} + +impl Iterator for ScopedIter { + type Item = T; + + fn next(&mut self) -> Option { + if self.cur_index >= self.last_index { + return None; + } + + let vec = unsafe{ &*self.inner }; + let index = self.cur_index as usize; + self.cur_index += 1; + return Some(vec[index]); + } } \ No newline at end of file