grafos_pipeline/
stage_id.rs

1use core::fmt;
2
3/// Unique identifier for a pipeline stage.
4#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
5pub struct StageId(u64);
6
7impl StageId {
8    /// Create a new stage identifier.
9    pub fn new(id: u64) -> Self {
10        Self(id)
11    }
12
13    /// Return the raw `u64` value.
14    pub fn value(&self) -> u64 {
15        self.0
16    }
17}
18
19impl fmt::Display for StageId {
20    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21        write!(f, "stage({})", self.0)
22    }
23}
24
25#[cfg(test)]
26mod tests {
27    use super::*;
28
29    #[test]
30    fn display() {
31        assert_eq!(format!("{}", StageId::new(7)), "stage(7)");
32    }
33
34    #[test]
35    fn eq_and_hash() {
36        use alloc::collections::BTreeSet;
37        let mut s = BTreeSet::new();
38        s.insert(StageId::new(1).value());
39        s.insert(StageId::new(2).value());
40        assert_eq!(s.len(), 2);
41
42        assert_eq!(StageId::new(3), StageId::new(3));
43        assert_ne!(StageId::new(3), StageId::new(4));
44    }
45}