diff options
| author | Mica White <botahamec@outlook.com> | 2026-08-26 20:46:31 -0400 |
|---|---|---|
| committer | Mica White <botahamec@outlook.com> | 2026-08-26 20:46:31 -0400 |
| commit | 55b3a2425b242fbc5c6e471f220eeb8b949e8751 (patch) | |
| tree | 5ceb7910b60cc7331024b7ce1d49ec259e0302a8 /src/iterator/iterator.rs | |
| parent | 6f6e030ea7edb9d155ebf21b5d42936c20801b50 (diff) | |
Add tests
Diffstat (limited to 'src/iterator/iterator.rs')
| -rw-r--r-- | src/iterator/iterator.rs | 118 |
1 files changed, 0 insertions, 118 deletions
diff --git a/src/iterator/iterator.rs b/src/iterator/iterator.rs deleted file mode 100644 index 316a276..0000000 --- a/src/iterator/iterator.rs +++ /dev/null @@ -1,118 +0,0 @@ -use std::iter::{Enumerate, Fuse, Skip, Take}; - -use super::{IteratorGuard, LockingIterator}; - -use crate::{ - lockable::{Lockable, RawLock, Sharable}, - ThreadKey, -}; - -impl<'l, I> LockingIterator<'l, I> { - fn with_iterator<M>(self, f: impl FnOnce(I) -> M) -> LockingIterator<'l, M> { - LockingIterator { - key: self.key, - iterator: f(self.iterator), - } - } -} - -impl<'c, L: 'c + Iterator<Item = &'c I>, I: 'c + RawLock + Lockable> LockingIterator<'c, L> { - pub fn lock_next( - &mut self, - ) -> Option<IteratorGuard<'c, <I as Lockable>::Guard<'c>, ThreadKey>> { - if let Some(lock) = self.iterator.next() { - unsafe { - lock.raw_write(); - let guard = lock.guard(); - - Some(IteratorGuard { - _key: self.key, - guard, - }) - } - } else { - None - } - } - - pub fn lock_last(self) -> Option<IteratorGuard<'c, <I as Lockable>::Guard<'c>, ThreadKey>> { - self.iterator.last().map(|lock| unsafe { - lock.raw_write(); - let guard = lock.guard(); - - IteratorGuard { - _key: self.key, - guard, - } - }) - } -} - -impl<'c, L: 'c + Iterator<Item = &'c I>, I: 'c + RawLock + Sharable> LockingIterator<'c, L> { - pub fn read_next( - &mut self, - ) -> Option<IteratorGuard<'c, <I as Sharable>::ReadGuard<'c>, ThreadKey>> { - if let Some(lock) = self.iterator.next() { - unsafe { - lock.raw_read(); - let guard = lock.read_guard(); - - Some(IteratorGuard { - _key: self.key, - guard, - }) - } - } else { - None - } - } - - pub fn read_last(self) -> Option<IteratorGuard<'c, <I as Sharable>::ReadGuard<'c>, ThreadKey>> { - self.iterator.last().map(|lock| unsafe { - lock.raw_read(); - let guard = lock.read_guard(); - - IteratorGuard { - _key: self.key, - guard, - } - }) - } -} - -impl<'l, L: Iterator> LockingIterator<'l, L> { - pub fn skip_next(&mut self) -> Option<L::Item> { - self.iterator.next() - } - - pub fn skip_mut(&mut self, n: usize) { - for _ in 0..n { - self.iterator.next(); - } - } - - #[must_use] - pub fn size_hint(&self) -> (usize, Option<usize>) { - self.iterator.size_hint() - } - - #[must_use] - pub fn enumerate(self) -> LockingIterator<'l, Enumerate<L>> { - self.with_iterator(Iterator::enumerate) - } - - #[must_use] - pub fn skip(self, n: usize) -> LockingIterator<'l, Skip<L>> { - self.with_iterator(|i| i.skip(n)) - } - - #[must_use] - pub fn take(self, n: usize) -> LockingIterator<'l, Take<L>> { - self.with_iterator(|i| i.take(n)) - } - - #[must_use] - pub fn fuse(self) -> LockingIterator<'l, Fuse<L>> { - self.with_iterator(Iterator::fuse) - } -} |
