use super::prelude::*;
use std::hash::{Hash, Hasher};
pub enum TerminalId<N: NetlistIds + ?Sized> {
PinId(N::PinId),
PinInstId(N::PinInstId),
}
impl<N1> TerminalId<N1>
where
N1: NetlistIds,
{
pub fn cast<N2>(self) -> TerminalId<N2>
where
N2: NetlistIds<PinId = N1::PinId, PinInstId = N1::PinInstId>,
{
match self {
TerminalId::PinId(p) => TerminalId::PinId(p),
TerminalId::PinInstId(p) => TerminalId::PinInstId(p),
}
}
}
impl<N: NetlistIds + ?Sized> std::fmt::Debug for TerminalId<N>
where
N::PinId: std::fmt::Debug,
N::PinInstId: std::fmt::Debug,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
TerminalId::PinId(p) => write!(f, "{:?}", p),
TerminalId::PinInstId(p) => write!(f, "{:?}", p),
}
}
}
impl<N: NetlistIds + ?Sized> Hash for TerminalId<N> {
fn hash<H: Hasher>(&self, state: &mut H) {
match self {
TerminalId::PinId(p) => p.hash(state),
TerminalId::PinInstId(p) => p.hash(state),
}
}
}
impl<N: NetlistIds + ?Sized> Eq for TerminalId<N> {}
impl<N: NetlistIds + ?Sized> PartialEq for TerminalId<N> {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::PinId(p1), Self::PinId(p2)) => p1 == p2,
(Self::PinInstId(p1), Self::PinInstId(p2)) => p1 == p2,
(_, _) => false,
}
}
}
impl<N: NetlistIds + ?Sized> Clone for TerminalId<N>
where
N::PinId: Clone,
N::PinInstId: Clone,
{
fn clone(&self) -> Self {
match self {
TerminalId::PinId(p) => Self::PinId(p.clone()),
TerminalId::PinInstId(p) => Self::PinInstId(p.clone()),
}
}
}