rtdlib/types/
vector_path_command.rs1
2use crate::types::*;
3use crate::errors::*;
4use uuid::Uuid;
5
6
7
8
9use std::fmt::Debug;
10use serde::de::{Deserialize, Deserializer};
11
12
13
14pub trait TDVectorPathCommand: Debug + RObject {}
16
17#[derive(Debug, Clone, Serialize)]
19#[serde(untagged)]
20pub enum VectorPathCommand {
21 #[doc(hidden)] _Default(()),
22 CubicBezierCurve(VectorPathCommandCubicBezierCurve),
24 Line(VectorPathCommandLine),
26
27}
28
29impl Default for VectorPathCommand {
30 fn default() -> Self { VectorPathCommand::_Default(()) }
31}
32
33impl<'de> Deserialize<'de> for VectorPathCommand {
34 fn deserialize<D>(deserializer: D) -> Result<VectorPathCommand, D::Error> where D: Deserializer<'de> {
35 use serde::de::Error;
36 rtd_enum_deserialize!(
37 VectorPathCommand,
38 (vectorPathCommandCubicBezierCurve, CubicBezierCurve);
39 (vectorPathCommandLine, Line);
40
41 )(deserializer)
42 }
43}
44
45impl RObject for VectorPathCommand {
46 #[doc(hidden)] fn td_name(&self) -> &'static str {
47 match self {
48 VectorPathCommand::CubicBezierCurve(t) => t.td_name(),
49 VectorPathCommand::Line(t) => t.td_name(),
50
51 _ => "-1",
52 }
53 }
54 #[doc(hidden)] fn extra(&self) -> Option<String> {
55 match self {
56 VectorPathCommand::CubicBezierCurve(t) => t.extra(),
57 VectorPathCommand::Line(t) => t.extra(),
58
59 _ => None,
60 }
61 }
62 fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
63}
64
65impl VectorPathCommand {
66 pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
67 #[doc(hidden)] pub fn _is_default(&self) -> bool { if let VectorPathCommand::_Default(_) = self { true } else { false } }
68
69 pub fn is_cubic_bezier_curve(&self) -> bool { if let VectorPathCommand::CubicBezierCurve(_) = self { true } else { false } }
70 pub fn is_line(&self) -> bool { if let VectorPathCommand::Line(_) = self { true } else { false } }
71
72 pub fn on_cubic_bezier_curve<F: FnOnce(&VectorPathCommandCubicBezierCurve)>(&self, fnc: F) -> &Self { if let VectorPathCommand::CubicBezierCurve(t) = self { fnc(t) }; self }
73 pub fn on_line<F: FnOnce(&VectorPathCommandLine)>(&self, fnc: F) -> &Self { if let VectorPathCommand::Line(t) = self { fnc(t) }; self }
74
75 pub fn as_cubic_bezier_curve(&self) -> Option<&VectorPathCommandCubicBezierCurve> { if let VectorPathCommand::CubicBezierCurve(t) = self { return Some(t) } None }
76 pub fn as_line(&self) -> Option<&VectorPathCommandLine> { if let VectorPathCommand::Line(t) = self { return Some(t) } None }
77
78
79
80 pub fn cubic_bezier_curve<T: AsRef<VectorPathCommandCubicBezierCurve>>(t: T) -> Self { VectorPathCommand::CubicBezierCurve(t.as_ref().clone()) }
81
82 pub fn line<T: AsRef<VectorPathCommandLine>>(t: T) -> Self { VectorPathCommand::Line(t.as_ref().clone()) }
83
84}
85
86impl AsRef<VectorPathCommand> for VectorPathCommand {
87 fn as_ref(&self) -> &VectorPathCommand { self }
88}
89
90
91
92
93
94
95
96#[derive(Debug, Clone, Default, Serialize, Deserialize)]
98pub struct VectorPathCommandCubicBezierCurve {
99 #[doc(hidden)]
100 #[serde(rename(serialize = "@type", deserialize = "@type"))]
101 td_name: String,
102 #[doc(hidden)]
103 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
104 extra: Option<String>,
105 start_control_point: Point,
107 end_control_point: Point,
109 end_point: Point,
111
112}
113
114impl RObject for VectorPathCommandCubicBezierCurve {
115 #[doc(hidden)] fn td_name(&self) -> &'static str { "vectorPathCommandCubicBezierCurve" }
116 #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
117 fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
118}
119
120
121impl TDVectorPathCommand for VectorPathCommandCubicBezierCurve {}
122
123
124
125impl VectorPathCommandCubicBezierCurve {
126 pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
127 pub fn builder() -> RTDVectorPathCommandCubicBezierCurveBuilder {
128 let mut inner = VectorPathCommandCubicBezierCurve::default();
129 inner.td_name = "vectorPathCommandCubicBezierCurve".to_string();
130 inner.extra = Some(Uuid::new_v4().to_string());
131 RTDVectorPathCommandCubicBezierCurveBuilder { inner }
132 }
133
134 pub fn start_control_point(&self) -> &Point { &self.start_control_point }
135
136 pub fn end_control_point(&self) -> &Point { &self.end_control_point }
137
138 pub fn end_point(&self) -> &Point { &self.end_point }
139
140}
141
142#[doc(hidden)]
143pub struct RTDVectorPathCommandCubicBezierCurveBuilder {
144 inner: VectorPathCommandCubicBezierCurve
145}
146
147impl RTDVectorPathCommandCubicBezierCurveBuilder {
148 pub fn build(&self) -> VectorPathCommandCubicBezierCurve { self.inner.clone() }
149
150
151 pub fn start_control_point<T: AsRef<Point>>(&mut self, start_control_point: T) -> &mut Self {
152 self.inner.start_control_point = start_control_point.as_ref().clone();
153 self
154 }
155
156
157 pub fn end_control_point<T: AsRef<Point>>(&mut self, end_control_point: T) -> &mut Self {
158 self.inner.end_control_point = end_control_point.as_ref().clone();
159 self
160 }
161
162
163 pub fn end_point<T: AsRef<Point>>(&mut self, end_point: T) -> &mut Self {
164 self.inner.end_point = end_point.as_ref().clone();
165 self
166 }
167
168}
169
170impl AsRef<VectorPathCommandCubicBezierCurve> for VectorPathCommandCubicBezierCurve {
171 fn as_ref(&self) -> &VectorPathCommandCubicBezierCurve { self }
172}
173
174impl AsRef<VectorPathCommandCubicBezierCurve> for RTDVectorPathCommandCubicBezierCurveBuilder {
175 fn as_ref(&self) -> &VectorPathCommandCubicBezierCurve { &self.inner }
176}
177
178
179
180
181
182
183
184#[derive(Debug, Clone, Default, Serialize, Deserialize)]
186pub struct VectorPathCommandLine {
187 #[doc(hidden)]
188 #[serde(rename(serialize = "@type", deserialize = "@type"))]
189 td_name: String,
190 #[doc(hidden)]
191 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
192 extra: Option<String>,
193 end_point: Point,
195
196}
197
198impl RObject for VectorPathCommandLine {
199 #[doc(hidden)] fn td_name(&self) -> &'static str { "vectorPathCommandLine" }
200 #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
201 fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
202}
203
204
205impl TDVectorPathCommand for VectorPathCommandLine {}
206
207
208
209impl VectorPathCommandLine {
210 pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
211 pub fn builder() -> RTDVectorPathCommandLineBuilder {
212 let mut inner = VectorPathCommandLine::default();
213 inner.td_name = "vectorPathCommandLine".to_string();
214 inner.extra = Some(Uuid::new_v4().to_string());
215 RTDVectorPathCommandLineBuilder { inner }
216 }
217
218 pub fn end_point(&self) -> &Point { &self.end_point }
219
220}
221
222#[doc(hidden)]
223pub struct RTDVectorPathCommandLineBuilder {
224 inner: VectorPathCommandLine
225}
226
227impl RTDVectorPathCommandLineBuilder {
228 pub fn build(&self) -> VectorPathCommandLine { self.inner.clone() }
229
230
231 pub fn end_point<T: AsRef<Point>>(&mut self, end_point: T) -> &mut Self {
232 self.inner.end_point = end_point.as_ref().clone();
233 self
234 }
235
236}
237
238impl AsRef<VectorPathCommandLine> for VectorPathCommandLine {
239 fn as_ref(&self) -> &VectorPathCommandLine { self }
240}
241
242impl AsRef<VectorPathCommandLine> for RTDVectorPathCommandLineBuilder {
243 fn as_ref(&self) -> &VectorPathCommandLine { &self.inner }
244}
245
246
247