use std::fmt;
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct FeedId(u64);
impl FeedId {
#[must_use]
pub fn new(val: u64) -> Self {
Self(val)
}
#[must_use]
pub fn as_u64(self) -> u64 {
self.0
}
}
impl fmt::Display for FeedId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "feed-{}", self.0)
}
}
impl fmt::Debug for FeedId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "FeedId({})", self.0)
}
}
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct TrackId(u64);
impl TrackId {
#[must_use]
pub fn new(val: u64) -> Self {
Self(val)
}
#[must_use]
pub fn as_u64(self) -> u64 {
self.0
}
}
impl fmt::Display for TrackId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "track-{}", self.0)
}
}
impl fmt::Debug for TrackId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "TrackId({})", self.0)
}
}
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct DetectionId(u64);
impl DetectionId {
#[must_use]
pub fn new(val: u64) -> Self {
Self(val)
}
#[must_use]
pub fn as_u64(self) -> u64 {
self.0
}
}
impl fmt::Display for DetectionId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "det-{}", self.0)
}
}
impl fmt::Debug for DetectionId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "DetectionId({})", self.0)
}
}
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct StageId(pub &'static str);
impl StageId {
#[must_use]
pub 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 fmt::Debug for StageId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "StageId(\"{}\")", self.0)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn feed_id_display() {
let id = FeedId::new(42);
assert_eq!(id.to_string(), "feed-42");
}
#[test]
fn stage_id_copy() {
let a = StageId("detector");
let b = a;
assert_eq!(a, b);
}
#[test]
fn ids_are_copy_and_eq() {
let t = TrackId::new(1);
let d = DetectionId::new(2);
assert_eq!(t, TrackId::new(1));
assert_eq!(d, DetectionId::new(2));
}
}