#[derive(Debug)]
pub enum EventError {
OverloadedEvent,
ListenerNotFound,
EventNotFound,
#[cfg(not(feature = "threaded"))]
Other(&'static str, u16),
#[cfg(feature = "threaded")]
Other(Box<dyn std::error::Error + Send + Sync>),
}
impl PartialEq for EventError {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(EventError::ListenerNotFound, EventError::ListenerNotFound)
| (EventError::EventNotFound, EventError::EventNotFound)
| (EventError::OverloadedEvent, EventError::OverloadedEvent) => true,
#[cfg(not(feature = "threaded"))]
(EventError::Other(a1, a2), EventError::Other(b1, b2)) => a1 == b1 && a2 == b2,
#[cfg(feature = "threaded")]
(EventError::Other(a), EventError::Other(b)) => a.to_string() == b.to_string(),
_ => false,
}
}
}
impl Eq for EventError {}
impl core::fmt::Display for EventError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
EventError::OverloadedEvent => write!(f, "Too many listeners for event"),
EventError::ListenerNotFound => write!(f, "Listener not found"),
EventError::EventNotFound => write!(f, "Event not found"),
#[cfg(not(feature = "threaded"))]
EventError::Other(msg, code) => write!(f, "Error: {} (code {})", msg, code),
#[cfg(feature = "threaded")]
EventError::Other(e) => write!(f, "Error: {}", e),
}
}
}
#[cfg(feature = "threaded")]
impl std::error::Error for EventError {}