1use crate::port::PortReference;
2use crate::schematic::ConnectionIndex;
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5#[must_use]
6pub struct Connection<DATA> {
7 pub(crate) from: PortReference,
8 pub(crate) to: PortReference,
9 pub(crate) index: ConnectionIndex,
10 pub(crate) data: DATA,
11}
12
13impl<DATA> Connection<DATA>
14where
15 DATA: Clone,
16{
17 pub(crate) const fn new(from: PortReference, to: PortReference, index: ConnectionIndex, data: DATA) -> Self {
18 Self { from, to, index, data }
19 }
20
21 #[must_use]
22 pub const fn index(&self) -> &ConnectionIndex {
23 &self.index
24 }
25
26 #[must_use]
27 pub const fn from(&self) -> &PortReference {
28 &self.from
29 }
30
31 #[must_use]
32 pub const fn to(&self) -> &PortReference {
33 &self.to
34 }
35
36 #[must_use]
37 pub const fn data(&self) -> &DATA {
38 &self.data
39 }
40}
41
42impl<DATA> std::fmt::Display for Connection<DATA> {
43 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
44 write!(f, "{}:{}=>{}", self.index, self.from, self.to)
45 }
46}