Skip to main content

melodium_share/
connection_design.rs

1use crate::Attributes;
2use melodium_engine::design::{Connection, IO};
3use serde::{Deserialize, Serialize};
4
5#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
6#[serde(rename_all = "snake_case")]
7#[cfg_attr(feature = "webassembly", derive(tsify::Tsify))]
8#[cfg_attr(feature = "webassembly", tsify(into_wasm_abi, from_wasm_abi))]
9pub enum IoDesign {
10    Sequence(),
11    Treatment(String),
12}
13
14impl From<&IO> for IoDesign {
15    fn from(value: &IO) -> Self {
16        match value {
17            IO::Sequence() => IoDesign::Sequence(),
18            IO::Treatment(name) => IoDesign::Treatment(name.clone()),
19        }
20    }
21}
22
23impl Into<IO> for &IoDesign {
24    fn into(self) -> IO {
25        match self {
26            IoDesign::Sequence() => IO::Sequence(),
27            IoDesign::Treatment(name) => IO::Treatment(name.clone()),
28        }
29    }
30}
31
32#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
33#[cfg_attr(feature = "webassembly", derive(tsify::Tsify))]
34#[cfg_attr(feature = "webassembly", tsify(into_wasm_abi, from_wasm_abi))]
35pub struct ConnectionDesign {
36    pub output_treatment: IoDesign,
37    pub output_name: String,
38
39    pub input_treatment: IoDesign,
40    pub input_name: String,
41
42    pub attributes: Attributes,
43}
44
45impl From<&Connection> for ConnectionDesign {
46    fn from(value: &Connection) -> Self {
47        Self {
48            output_treatment: (&value.output_treatment).into(),
49            output_name: value.output_name.clone(),
50            input_treatment: (&value.input_treatment).into(),
51            input_name: value.input_name.clone(),
52            attributes: (&value.attributes).into(),
53        }
54    }
55}
56
57impl Into<Connection> for &ConnectionDesign {
58    fn into(self) -> Connection {
59        Connection {
60            output_treatment: (&self.output_treatment).into(),
61            output_name: self.output_name.clone(),
62            input_treatment: (&self.input_treatment).into(),
63            input_name: self.input_name.clone(),
64            attributes: (&self.attributes).into(),
65        }
66    }
67}