use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Disconnected;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WaitTimeoutError {
Timeout,
Disconnected,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TryWaitError {
Pending,
Disconnected,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct NoReceivers;
impl WaitTimeoutError {
#[inline]
pub fn is_disconnected(self) -> bool {
matches!(self, WaitTimeoutError::Disconnected)
}
#[inline]
pub fn is_timeout(self) -> bool {
matches!(self, WaitTimeoutError::Timeout)
}
}
impl TryWaitError {
#[inline]
pub fn is_pending(self) -> bool {
matches!(self, TryWaitError::Pending)
}
#[inline]
pub fn is_disconnected(self) -> bool {
matches!(self, TryWaitError::Disconnected)
}
}
impl fmt::Display for Disconnected {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("all signalers dropped without firing")
}
}
impl fmt::Display for WaitTimeoutError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
WaitTimeoutError::Timeout => f.write_str("timed out before the event fired"),
WaitTimeoutError::Disconnected => f.write_str("all signalers dropped without firing"),
}
}
}
impl fmt::Display for TryWaitError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TryWaitError::Pending => f.write_str("event has not fired yet"),
TryWaitError::Disconnected => f.write_str("all signalers dropped without firing"),
}
}
}
impl fmt::Display for NoReceivers {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("all waiters dropped; no one can receive the signal")
}
}
impl std::error::Error for Disconnected {}
impl std::error::Error for WaitTimeoutError {}
impl std::error::Error for TryWaitError {}
impl std::error::Error for NoReceivers {}
impl From<Disconnected> for WaitTimeoutError {
fn from(_: Disconnected) -> Self {
WaitTimeoutError::Disconnected
}
}
impl From<Disconnected> for TryWaitError {
fn from(_: Disconnected) -> Self {
TryWaitError::Disconnected
}
}