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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use tydi_intern::Id;
use crate::{
identifier::Identifier,
net::{Connection, Net},
Type,
};
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Component {
pub identifier: Id<Identifier>,
pub instances: Vec<Id<Instance>>,
pub nets: Vec<Id<Net>>,
pub connections: Vec<Connection>,
pub types: Vec<Id<Type>>,
pub metadata: Vec<(String, String)>,
}
impl Component {
pub fn new(identifier: Id<Identifier>) -> Self {
Self {
identifier,
instances: vec![],
nets: vec![],
connections: vec![],
metadata: vec![],
types: vec![],
}
}
pub fn with_instance(mut self, instance: Id<Instance>) -> Self {
self.instances.push(instance);
self
}
pub fn with_net(mut self, net: Id<Net>) -> Self {
self.nets.push(net);
self
}
pub fn with_connection(mut self, connection: Connection) -> Self {
self.connections.push(connection);
self
}
pub fn with_metadata<T: Into<String>>(mut self, key: T, value: T) -> Self {
self.metadata.push((key.into(), value.into()));
self
}
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Instance {
pub identifier: Id<Identifier>,
pub component: Id<Component>,
}
impl Instance {
pub fn new(identifier: Id<Identifier>, component: Id<Component>) -> Self {
Self {
identifier,
component,
}
}
}