1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//! Unique identifiers for circuits.

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

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

impl UniqId {
    /// Construct a new circuit UniqId from its parts
    pub(crate) fn new(chan: usize, circ: usize) -> Self {
        UniqId { chan, circ }
    }
}

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