1
//! Unique identifiers for circuits.
2

            
3
use std::fmt::{Display, Formatter};
4

            
5
/// Process-unique identifier for a circuit.
6
///
7
/// We could use channel_id.circid here, but the circid can be reused
8
/// over time.  This won't ever repeat on a 64-bit architecture, and
9
/// is super-unlikely to repeat on a 32-bit architecture.  (If
10
/// we're about to return a repeat value, we assert instead.)
11
32
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
12
pub struct UniqId {
13
    /// Channel that this circuit is on.
14
    chan: usize,
15
    /// ID for the circuit on the channel
16
    circ: usize,
17
}
18

            
19
impl UniqId {
20
    /// Construct a new circuit UniqId from its parts
21
51
    pub(crate) fn new(chan: usize, circ: usize) -> Self {
22
51
        UniqId { chan, circ }
23
51
    }
24
}
25

            
26
impl Display for UniqId {
27
1
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
28
1
        write!(f, "Circ {}.{}", self.chan, self.circ)
29
1
    }
30
}