diff options
| author | Mica White <botahamec@outlook.com> | 2026-03-14 20:37:26 -0400 |
|---|---|---|
| committer | Mica White <botahamec@outlook.com> | 2026-03-14 20:37:26 -0400 |
| commit | d9095d8fce59714f75019ecf68911d9931a1af15 (patch) | |
| tree | 7f466b2d61b437c5b6721aa030a7518cf7e690eb /src/iterator/consumed_guard.rs | |
| parent | fbdfc775bd1642a469f8a3fa0aa9beb91ca760d6 (diff) | |
Basic scoped lock and guard implementations
Diffstat (limited to 'src/iterator/consumed_guard.rs')
| -rw-r--r-- | src/iterator/consumed_guard.rs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/iterator/consumed_guard.rs b/src/iterator/consumed_guard.rs new file mode 100644 index 0000000..5331289 --- /dev/null +++ b/src/iterator/consumed_guard.rs @@ -0,0 +1,58 @@ +use std::fmt::{Debug, Display}; +use std::hash::Hash; +use std::ops::{Deref, DerefMut}; + +use crate::iterator::ConsumedIteratorGuard; + +#[mutants::skip] // hashing involves RNG and is hard to test +#[cfg(not(tarpaulin_include))] +impl<Guard: Hash, Key> Hash for ConsumedIteratorGuard<Guard, Key> { + fn hash<H: std::hash::Hasher>(&self, state: &mut H) { + self.guard.hash(state) + } +} + +// No implementations of Eq, PartialEq, PartialOrd, or Ord +// You can't implement both PartialEq<Self> and PartialEq<T> +// It's easier to just implement neither and ask users to dereference +// This is less of a problem when using the scoped lock API + +#[mutants::skip] +#[cfg(not(tarpaulin_include))] +impl<Guard: Debug, Key> Debug for ConsumedIteratorGuard<Guard, Key> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + Debug::fmt(&**self, f) + } +} + +impl<Guard: Display, Key> Display for ConsumedIteratorGuard<Guard, Key> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + Display::fmt(&**self, f) + } +} + +impl<Guard, Key> Deref for ConsumedIteratorGuard<Guard, Key> { + type Target = Guard; + + fn deref(&self) -> &Self::Target { + &self.guard + } +} + +impl<Guard, Key> DerefMut for ConsumedIteratorGuard<Guard, Key> { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.guard + } +} + +impl<Guard, Key> AsRef<Guard> for ConsumedIteratorGuard<Guard, Key> { + fn as_ref(&self) -> &Guard { + &self.guard + } +} + +impl<Guard, Key> AsMut<Guard> for ConsumedIteratorGuard<Guard, Key> { + fn as_mut(&mut self) -> &mut Guard { + &mut self.guard + } +} |
