daedalus_runtime/
handles.rs1#[derive(Clone, Debug)]
9pub struct PortHandle {
10 pub node_alias: String,
11 pub port: String,
12}
13
14impl PortHandle {
15 pub fn new(node_alias: impl Into<String>, port: impl Into<String>) -> Self {
17 Self {
18 node_alias: node_alias.into(),
19 port: port.into(),
20 }
21 }
22}
23
24#[derive(Clone, Debug)]
32pub struct NodeHandle {
33 pub id: String,
34 pub alias: String,
35}
36
37impl NodeHandle {
38 pub fn new(id: impl Into<String>) -> Self {
40 let id = id.into();
41 Self {
42 alias: id.clone(),
43 id,
44 }
45 }
46
47 pub fn alias(&self, alias: impl Into<String>) -> Self {
49 let mut cloned = self.clone();
50 cloned.alias = alias.into();
51 cloned
52 }
53
54 pub fn input(&self, name: impl Into<String>) -> PortHandle {
56 PortHandle::new(self.alias.clone(), name)
57 }
58
59 pub fn output(&self, name: impl Into<String>) -> PortHandle {
61 PortHandle::new(self.alias.clone(), name)
62 }
63}
64
65pub trait NodeHandleLike {
73 fn id(&self) -> &str;
74 fn alias(&self) -> &str;
75}
76
77impl NodeHandleLike for NodeHandle {
78 fn id(&self) -> &str {
79 &self.id
80 }
81
82 fn alias(&self) -> &str {
83 &self.alias
84 }
85}
86
87impl<T> NodeHandleLike for &T
88where
89 T: NodeHandleLike + ?Sized,
90{
91 fn id(&self) -> &str {
92 (*self).id()
93 }
94
95 fn alias(&self) -> &str {
96 (*self).alias()
97 }
98}