1use crate::prelude::*;
2
3#[derive(Debug, Clone, PartialEq, Eq, Hash)]
5pub struct InputLayout {
6 pub label: String,
7 pub uuid: Uuid,
8}
9
10#[derive(Debug, Clone, PartialEq, Eq, Hash)]
12pub struct OutputLayout {
13 pub label: String,
14 pub uuid: Uuid,
15}
16
17#[derive(Debug, Clone, PartialEq, Eq, Hash)]
19pub struct QueryLayout {
20 pub label: String,
21 pub uuid: Uuid,
22}
23
24#[derive(Debug, Clone, PartialEq, Eq, Hash)]
26pub struct QueryableLayout {
27 pub label: String,
28 pub uuid: Uuid,
29}
30
31#[derive(Debug, Clone, PartialEq, Eq, Hash)]
33pub enum IOLayout {
34 Input(InputLayout),
35 Output(OutputLayout),
36 Query(QueryLayout),
37 Queryable(QueryableLayout),
38}
39
40macro_rules! impl_into_nodeio {
41 ($($ty:ty => $variant:ident),*) => {
42 $(
43 impl From<$ty> for IOLayout {
44 fn from(value: $ty) -> IOLayout {
45 IOLayout::$variant(value)
46 }
47 }
48
49 impl From<&$ty> for IOLayout {
50 fn from(value: &$ty) -> IOLayout {
51 IOLayout::$variant(value.clone())
52 }
53 }
54 )*
55 };
56}
57
58impl_into_nodeio!(
59 InputLayout => Input,
60 OutputLayout => Output,
61 QueryLayout => Query,
62 QueryableLayout => Queryable
63);
64
65macro_rules! impl_into_uuid {
66 ($($ty:ty),*) => {
67 $(
68 impl From<$ty> for Uuid {
69 fn from(value: $ty) -> Uuid {
70 value.uuid
71 }
72 }
73
74 impl From<&$ty> for Uuid {
75 fn from(value: &$ty) -> Uuid {
76 value.uuid
77 }
78 }
79 )*
80 };
81}
82
83impl_into_uuid!(InputLayout, OutputLayout, QueryLayout, QueryableLayout);
84
85impl IOLayout {
86 pub fn label(&self) -> String {
88 match self {
89 IOLayout::Input(input) => input.label.clone(),
90 IOLayout::Output(output) => output.label.clone(),
91 IOLayout::Query(query) => query.label.clone(),
92 IOLayout::Queryable(queryable) => queryable.label.clone(),
93 }
94 }
95
96 pub fn uuid(&self) -> Uuid {
98 match self {
99 IOLayout::Input(input) => input.uuid,
100 IOLayout::Output(output) => output.uuid,
101 IOLayout::Query(query) => query.uuid,
102 IOLayout::Queryable(queryable) => queryable.uuid,
103 }
104 }
105}
106
107impl TryFrom<IOLayout> for InputLayout {
108 type Error = eyre::Report;
109
110 fn try_from(value: IOLayout) -> eyre::Result<Self> {
111 match value {
112 IOLayout::Input(layout) => Ok(layout),
113 _ => Err(eyre::eyre!("Invalid type")),
114 }
115 }
116}
117
118impl TryFrom<IOLayout> for OutputLayout {
119 type Error = eyre::Report;
120
121 fn try_from(value: IOLayout) -> eyre::Result<Self> {
122 match value {
123 IOLayout::Output(layout) => Ok(layout),
124 _ => Err(eyre::eyre!("Invalid type")),
125 }
126 }
127}
128
129impl TryFrom<IOLayout> for QueryLayout {
130 type Error = eyre::Report;
131
132 fn try_from(value: IOLayout) -> eyre::Result<Self> {
133 match value {
134 IOLayout::Query(layout) => Ok(layout),
135 _ => Err(eyre::eyre!("Invalid type")),
136 }
137 }
138}
139
140impl TryFrom<IOLayout> for QueryableLayout {
141 type Error = eyre::Report;
142
143 fn try_from(value: IOLayout) -> eyre::Result<Self> {
144 match value {
145 IOLayout::Queryable(layout) => Ok(layout),
146 _ => Err(eyre::eyre!("Invalid type")),
147 }
148 }
149}
150
151impl From<IOLayout> for Uuid {
152 fn from(val: IOLayout) -> Self {
153 match val {
154 IOLayout::Input(input) => input.uuid,
155 IOLayout::Output(output) => output.uuid,
156 IOLayout::Query(query) => query.uuid,
157 IOLayout::Queryable(queryable) => queryable.uuid,
158 }
159 }
160}
161
162impl From<&IOLayout> for Uuid {
163 fn from(val: &IOLayout) -> Self {
164 match val {
165 IOLayout::Input(input) => input.uuid,
166 IOLayout::Output(output) => output.uuid,
167 IOLayout::Query(query) => query.uuid,
168 IOLayout::Queryable(queryable) => queryable.uuid,
169 }
170 }
171}