summaryrefslogtreecommitdiff
path: root/src/context/guard.rs
diff options
context:
space:
mode:
authorMica White <botahamec@outlook.com>2026-08-26 20:46:31 -0400
committerMica White <botahamec@outlook.com>2026-08-26 20:46:31 -0400
commit55b3a2425b242fbc5c6e471f220eeb8b949e8751 (patch)
tree5ceb7910b60cc7331024b7ce1d49ec259e0302a8 /src/context/guard.rs
parent6f6e030ea7edb9d155ebf21b5d42936c20801b50 (diff)
Add tests
Diffstat (limited to 'src/context/guard.rs')
-rw-r--r--src/context/guard.rs58
1 files changed, 58 insertions, 0 deletions
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<Guard: Hash, Key> Hash for ContextGuard<'_, 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 ContextGuard<'_, Guard, Key> {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ Debug::fmt(&**self, f)
+ }
+}
+
+impl<Guard: Display, Key> Display for ContextGuard<'_, Guard, Key> {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ Display::fmt(&**self, f)
+ }
+}
+
+impl<Guard, Key> Deref for ContextGuard<'_, Guard, Key> {
+ type Target = Guard;
+
+ fn deref(&self) -> &Self::Target {
+ &self.guard
+ }
+}
+
+impl<Guard, Key> DerefMut for ContextGuard<'_, Guard, Key> {
+ fn deref_mut(&mut self) -> &mut Self::Target {
+ &mut self.guard
+ }
+}
+
+impl<Guard, Key> AsRef<Guard> for ContextGuard<'_, Guard, Key> {
+ fn as_ref(&self) -> &Guard {
+ &self.guard
+ }
+}
+
+impl<Guard, Key> AsMut<Guard> for ContextGuard<'_, Guard, Key> {
+ fn as_mut(&mut self) -> &mut Guard {
+ &mut self.guard
+ }
+}