From 55b3a2425b242fbc5c6e471f220eeb8b949e8751 Mon Sep 17 00:00:00 2001 From: Mica White Date: Wed, 26 Aug 2026 20:46:31 -0400 Subject: Add tests --- src/context/guard.rs | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/context/guard.rs (limited to 'src/context/guard.rs') diff --git a/src/context/guard.rs b/src/context/guard.rs new file mode 100644 index 0000000..0898c1f --- /dev/null +++ b/src/context/guard.rs @@ -0,0 +1,58 @@ +use std::fmt::{Debug, Display}; +use std::hash::Hash; +use std::ops::{Deref, DerefMut}; + +use super::ContextGuard; + +#[mutants::skip] // hashing involves RNG and is hard to test +#[cfg(not(tarpaulin_include))] +impl Hash for ContextGuard<'_, Guard, Key> { + fn hash(&self, state: &mut H) { + self.guard.hash(state) + } +} + +// No implementations of Eq, PartialEq, PartialOrd, or Ord +// You can't implement both PartialEq and PartialEq +// 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 Debug for ContextGuard<'_, Guard, Key> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + Debug::fmt(&**self, f) + } +} + +impl Display for ContextGuard<'_, Guard, Key> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + Display::fmt(&**self, f) + } +} + +impl Deref for ContextGuard<'_, Guard, Key> { + type Target = Guard; + + fn deref(&self) -> &Self::Target { + &self.guard + } +} + +impl DerefMut for ContextGuard<'_, Guard, Key> { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.guard + } +} + +impl AsRef for ContextGuard<'_, Guard, Key> { + fn as_ref(&self) -> &Guard { + &self.guard + } +} + +impl AsMut for ContextGuard<'_, Guard, Key> { + fn as_mut(&mut self) -> &mut Guard { + &mut self.guard + } +} -- cgit v1.3.1