use core::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct StageId(&'static str);
impl StageId {
#[must_use]
pub const fn new(name: &'static str) -> Self {
Self(name)
}
#[must_use]
pub const fn as_str(&self) -> &'static str {
self.0
}
}
impl fmt::Display for StageId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.0)
}
}
impl From<&'static str> for StageId {
fn from(value: &'static str) -> Self {
Self::new(value)
}
}
#[cfg(test)]
mod tests {
use super::*;
use alloc::format;
#[test]
fn new_and_as_str_roundtrip() {
let id = StageId::new("ingest");
assert_eq!(id.as_str(), "ingest");
}
#[test]
fn display_writes_name() {
let id = StageId::new("ingest");
assert_eq!(format!("{id}"), "ingest");
}
#[test]
fn from_static_str() {
let id: StageId = "downstream".into();
assert_eq!(id.as_str(), "downstream");
}
#[test]
fn equality_by_name() {
assert_eq!(StageId::new("a"), StageId::new("a"));
assert_ne!(StageId::new("a"), StageId::new("b"));
}
}