1use serde::{Deserialize, Serialize};
2use uuid::Uuid;
3
4macro_rules! item_id {
5 ($ident:ident, $name:literal, $name_field:literal, $uuid_field:literal) => {
6 #[doc = concat!("Identifier of the", $name, ".")]
7 #[derive(
8 Clone, Debug, Default, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize,
9 )]
10 pub struct $ident {
11 #[doc = concat!("Name of the", $name, ".")]
12 #[serde(rename = $name_field)]
13 pub name: String,
14 #[doc = concat!("UUID of the", $name, ".")]
15 #[serde(rename = $uuid_field)]
16 pub uuid: Uuid,
17 }
18
19 impl PartialEq<$ident> for String {
20 fn eq(&self, other: &$ident) -> bool {
21 other == self.as_str()
22 }
23 }
24
25 impl PartialEq<$ident> for &str {
26 fn eq(&self, other: &$ident) -> bool {
27 other == *self
28 }
29 }
30
31 impl PartialEq<$ident> for Uuid {
32 fn eq(&self, other: &$ident) -> bool {
33 other == self
34 }
35 }
36
37 impl PartialEq<str> for $ident {
38 fn eq(&self, other: &str) -> bool {
39 self.name == other
40 }
41 }
42
43 impl PartialEq<Uuid> for $ident {
44 fn eq(&self, other: &Uuid) -> bool {
45 self.uuid == *other
46 }
47 }
48 };
49}
50
51item_id!(InputId, "input", "inputName", "inputUuid");
52item_id!(SceneId, "scene", "sceneName", "sceneUuid");
53item_id!(SourceId, "source", "sourceName", "sourceUuid");
54item_id!(
55 TransitionId,
56 "transition",
57 "transitionName",
58 "transitionUuid"
59);
60
61item_id!(
62 CurrentPreviewSceneId,
63 "current preview scene",
64 "currentPreviewSceneName",
65 "currentPreviewSceneUuid"
66);
67item_id!(
68 CurrentProgramSceneId,
69 "current program scene",
70 "currentProgramSceneName",
71 "currentProgramSceneUuid"
72);
73item_id!(
74 CurrentSceneTransitionId,
75 "current scene transition",
76 "currentSceneTransitionName",
77 "currentSceneTransitionUuid"
78);
79
80macro_rules! convert {
81 ($source:ident, $target:ident) => {
82 impl From<$source> for $target {
83 fn from(value: $source) -> Self {
84 Self {
85 name: value.name,
86 uuid: value.uuid,
87 }
88 }
89 }
90
91 impl From<$target> for $source {
92 fn from(value: $target) -> Self {
93 Self {
94 name: value.name,
95 uuid: value.uuid,
96 }
97 }
98 }
99 };
100}
101
102convert!(SceneId, CurrentPreviewSceneId);
103convert!(SceneId, CurrentProgramSceneId);
104convert!(CurrentPreviewSceneId, CurrentProgramSceneId);
105convert!(TransitionId, CurrentSceneTransitionId);
106
107macro_rules! request {
108 ($ident:ident) => {
109 impl From<$ident> for crate::requests::ids::$ident<'_> {
110 fn from(value: $ident) -> Self {
111 Self::Uuid(value.uuid)
112 }
113 }
114
115 impl From<&$ident> for crate::requests::ids::$ident<'_> {
116 fn from(value: &$ident) -> Self {
117 Self::Uuid(value.uuid)
118 }
119 }
120
121 impl PartialEq<$ident> for crate::requests::ids::$ident<'_> {
122 fn eq(&self, other: &$ident) -> bool {
123 match *self {
124 Self::Name(name) => name == other.name,
125 Self::Uuid(uuid) => uuid == other.uuid,
126 }
127 }
128 }
129
130 impl PartialEq<crate::requests::ids::$ident<'_>> for $ident {
131 fn eq(&self, other: &crate::requests::ids::$ident<'_>) -> bool {
132 other == self
133 }
134 }
135 };
136}
137
138request!(InputId);
139request!(SceneId);
140request!(SourceId);
141request!(TransitionId);