use serde::Serialize;
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum HookPhase {
Startup,
Shutdown,
}
impl std::fmt::Display for HookPhase {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Startup => f.write_str("startup"),
Self::Shutdown => f.write_str("shutdown"),
}
}
}
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize)]
pub struct GuardDescriptor {
pub code: String,
}
impl GuardDescriptor {
pub fn new(code: impl Into<String>) -> Self {
Self { code: code.into() }
}
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
pub struct HookDescriptor {
pub phase: HookPhase,
pub name: String,
pub order: u32,
}
impl HookDescriptor {
pub fn new(phase: HookPhase, name: impl Into<String>, order: u32) -> Self {
Self {
phase,
name: name.into(),
order,
}
}
#[must_use]
pub(crate) fn order_key(&self) -> (HookPhase, u32, &str) {
(self.phase, self.order, self.name.as_str())
}
}
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize)]
pub struct JobDescriptor {
pub kind: String,
}
impl JobDescriptor {
pub fn new(kind: impl Into<String>) -> Self {
Self { kind: kind.into() }
}
}