#![forbid(unsafe_code)]
#![doc = include_str!("../README.md")]
use core::fmt;
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum EventStatus {
#[default]
Pending,
Emitted,
Received,
Handled,
Ignored,
Failed,
}
impl EventStatus {
pub const fn as_str(self) -> &'static str {
match self {
Self::Pending => "pending",
Self::Emitted => "emitted",
Self::Received => "received",
Self::Handled => "handled",
Self::Ignored => "ignored",
Self::Failed => "failed",
}
}
pub const fn is_terminal(self) -> bool {
matches!(self, Self::Handled | Self::Ignored | Self::Failed)
}
pub const fn is_failure(self) -> bool {
matches!(self, Self::Failed)
}
}
impl fmt::Display for EventStatus {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str((*self).as_str())
}
}
#[cfg(test)]
mod tests {
use super::EventStatus;
#[test]
fn exposes_status_labels() {
assert_eq!(EventStatus::Pending.as_str(), "pending");
assert_eq!(EventStatus::Handled.to_string(), "handled");
}
#[test]
fn identifies_terminal_statuses() {
assert!(!EventStatus::Pending.is_terminal());
assert!(EventStatus::Handled.is_terminal());
assert!(EventStatus::Ignored.is_terminal());
assert!(EventStatus::Failed.is_terminal());
}
#[test]
fn identifies_failure_status() {
assert!(!EventStatus::Handled.is_failure());
assert!(EventStatus::Failed.is_failure());
}
}