summaryrefslogtreecommitdiff
path: root/src/context/guard.rs
blob: 6cd80edb12454105f74387d75e6104725e4b212b (plain)
use core::fmt::{Debug, Display};
use core::hash::Hash;
use core::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: core::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 core::fmt::Formatter<'_>) -> core::fmt::Result {
		Debug::fmt(&**self, f)
	}
}

impl<Guard: Display, Key> Display for ContextGuard<'_, Guard, Key> {
	fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::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
	}
}