libreda_db/netlist/
terminal_id.rs1use super::prelude::*;
9use std::hash::{Hash, Hasher};
10
11pub enum TerminalId<N: NetlistIds + ?Sized> {
13 PinId(N::PinId),
15 PinInstId(N::PinInstId),
17}
18
19impl<N1> TerminalId<N1>
20where
21 N1: NetlistIds,
22{
23 pub fn cast<N2>(self) -> TerminalId<N2>
25 where
26 N2: NetlistIds<PinId = N1::PinId, PinInstId = N1::PinInstId>,
27 {
28 match self {
29 TerminalId::PinId(p) => TerminalId::PinId(p),
30 TerminalId::PinInstId(p) => TerminalId::PinInstId(p),
31 }
32 }
33}
34
35impl<N: NetlistIds + ?Sized> std::fmt::Debug for TerminalId<N>
36where
37 N::PinId: std::fmt::Debug,
38 N::PinInstId: std::fmt::Debug,
39{
40 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41 match self {
42 TerminalId::PinId(p) => write!(f, "{:?}", p),
43 TerminalId::PinInstId(p) => write!(f, "{:?}", p),
44 }
45 }
46}
47
48impl<N: NetlistIds + ?Sized> Hash for TerminalId<N> {
49 fn hash<H: Hasher>(&self, state: &mut H) {
50 match self {
51 TerminalId::PinId(p) => p.hash(state),
52 TerminalId::PinInstId(p) => p.hash(state),
53 }
54 }
55}
56
57impl<N: NetlistIds + ?Sized> Eq for TerminalId<N> {}
58
59impl<N: NetlistIds + ?Sized> PartialEq for TerminalId<N> {
60 fn eq(&self, other: &Self) -> bool {
61 match (self, other) {
62 (Self::PinId(p1), Self::PinId(p2)) => p1 == p2,
63 (Self::PinInstId(p1), Self::PinInstId(p2)) => p1 == p2,
64 (_, _) => false,
65 }
66 }
67}
68
69impl<N: NetlistIds + ?Sized> Clone for TerminalId<N>
70where
71 N::PinId: Clone,
72 N::PinInstId: Clone,
73{
74 fn clone(&self) -> Self {
75 match self {
76 TerminalId::PinId(p) => Self::PinId(p.clone()),
77 TerminalId::PinInstId(p) => Self::PinInstId(p.clone()),
78 }
79 }
80}