use core::fmt;
use std::error::Error;
use super::{PoisonError, PoisonGuard, TryLockPoisonableError};
#[mutants::skip]
#[cfg(not(tarpaulin_include))]
impl<Guard> fmt::Debug for PoisonError<Guard> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("PoisonError").finish_non_exhaustive()
}
}
impl<Guard> fmt::Display for PoisonError<Guard> {
#[cfg_attr(test, mutants::skip)]
#[cfg(not(tarpaulin_include))]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
"poisoned lock: another task failed inside".fmt(f)
}
}
impl<Guard> AsRef<Guard> for PoisonError<Guard> {
fn as_ref(&self) -> &Guard {
self.get_ref()
}
}
impl<Guard> AsMut<Guard> for PoisonError<Guard> {
fn as_mut(&mut self) -> &mut Guard {
self.get_mut()
}
}
impl<Guard> Error for PoisonError<Guard> {}
impl<Guard> PoisonError<Guard> {
#[must_use]
pub const fn new(guard: Guard) -> Self {
Self { guard }
}
#[must_use]
pub fn into_inner(self) -> Guard {
self.guard
}
#[must_use]
pub const fn get_ref(&self) -> &Guard {
&self.guard
}
#[must_use]
pub fn get_mut(&mut self) -> &mut Guard {
&mut self.guard
}
}
#[mutants::skip]
#[cfg(not(tarpaulin_include))]
impl<G> fmt::Debug for TryLockPoisonableError<'_, G> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Self::Poisoned(..) => "Poisoned(..)".fmt(f),
Self::WouldBlock(_) => "WouldBlock".fmt(f),
}
}
}
impl<G> fmt::Display for TryLockPoisonableError<'_, G> {
#[cfg_attr(test, mutants::skip)]
#[cfg(not(tarpaulin_include))]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Self::Poisoned(..) => "poisoned lock: another task failed inside",
Self::WouldBlock(_) => "try_lock failed because the operation would block",
}
.fmt(f)
}
}
impl<G> Error for TryLockPoisonableError<'_, G> {}
impl<'flag, G> From<PoisonError<PoisonGuard<'flag, G>>> for TryLockPoisonableError<'flag, G> {
fn from(value: PoisonError<PoisonGuard<'flag, G>>) -> Self {
Self::Poisoned(value)
}
}