#![forbid(unsafe_code)]
#![doc = include_str!("../README.md")]
use core::fmt;
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum EventKind {
Created,
Updated,
Deleted,
Started,
Finished,
Failed,
Received,
Emitted,
Custom(String),
}
impl EventKind {
pub fn custom(value: impl Into<String>) -> Self {
Self::Custom(value.into())
}
pub fn as_str(&self) -> &str {
match self {
Self::Created => "created",
Self::Updated => "updated",
Self::Deleted => "deleted",
Self::Started => "started",
Self::Finished => "finished",
Self::Failed => "failed",
Self::Received => "received",
Self::Emitted => "emitted",
Self::Custom(value) => value.as_str(),
}
}
}
impl fmt::Display for EventKind {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(self.as_str())
}
}
#[cfg(test)]
mod tests {
use super::EventKind;
#[test]
fn exposes_standard_kind_labels() {
assert_eq!(EventKind::Created.as_str(), "created");
assert_eq!(EventKind::Started.to_string(), "started");
assert_eq!(EventKind::Failed.as_str(), "failed");
}
#[test]
fn supports_custom_kind_labels() {
let kind = EventKind::custom("checkpoint");
assert_eq!(kind.as_str(), "checkpoint");
assert_eq!(kind.to_string(), "checkpoint");
}
}