rust_tdlib/types/
vector_path_command.rs1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5use std::fmt::Debug;
6
7pub trait TDVectorPathCommand: Debug + RObject {}
9
10#[derive(Debug, Clone, Deserialize, Serialize, Default)]
12#[serde(tag = "@type")]
13pub enum VectorPathCommand {
14 #[doc(hidden)]
15 #[default]
16 _Default,
17 #[serde(rename = "vectorPathCommandCubicBezierCurve")]
19 CubicBezierCurve(VectorPathCommandCubicBezierCurve),
20 #[serde(rename = "vectorPathCommandLine")]
22 Line(VectorPathCommandLine),
23}
24
25impl RObject for VectorPathCommand {
26 #[doc(hidden)]
27 fn extra(&self) -> Option<&str> {
28 match self {
29 VectorPathCommand::CubicBezierCurve(t) => t.extra(),
30 VectorPathCommand::Line(t) => t.extra(),
31
32 _ => None,
33 }
34 }
35 #[doc(hidden)]
36 fn client_id(&self) -> Option<i32> {
37 match self {
38 VectorPathCommand::CubicBezierCurve(t) => t.client_id(),
39 VectorPathCommand::Line(t) => t.client_id(),
40
41 _ => None,
42 }
43 }
44}
45
46impl VectorPathCommand {
47 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
48 Ok(serde_json::from_str(json.as_ref())?)
49 }
50 #[doc(hidden)]
51 pub fn _is_default(&self) -> bool {
52 matches!(self, VectorPathCommand::_Default)
53 }
54}
55
56impl AsRef<VectorPathCommand> for VectorPathCommand {
57 fn as_ref(&self) -> &VectorPathCommand {
58 self
59 }
60}
61
62#[derive(Debug, Clone, Default, Serialize, Deserialize)]
64pub struct VectorPathCommandCubicBezierCurve {
65 #[doc(hidden)]
66 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
67 extra: Option<String>,
68 #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
69 client_id: Option<i32>,
70 start_control_point: Point,
72 end_control_point: Point,
74 end_point: Point,
76}
77
78impl RObject for VectorPathCommandCubicBezierCurve {
79 #[doc(hidden)]
80 fn extra(&self) -> Option<&str> {
81 self.extra.as_deref()
82 }
83 #[doc(hidden)]
84 fn client_id(&self) -> Option<i32> {
85 self.client_id
86 }
87}
88
89impl TDVectorPathCommand for VectorPathCommandCubicBezierCurve {}
90
91impl VectorPathCommandCubicBezierCurve {
92 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
93 Ok(serde_json::from_str(json.as_ref())?)
94 }
95 pub fn builder() -> VectorPathCommandCubicBezierCurveBuilder {
96 let mut inner = VectorPathCommandCubicBezierCurve::default();
97 inner.extra = Some(Uuid::new_v4().to_string());
98
99 VectorPathCommandCubicBezierCurveBuilder { inner }
100 }
101
102 pub fn start_control_point(&self) -> &Point {
103 &self.start_control_point
104 }
105
106 pub fn end_control_point(&self) -> &Point {
107 &self.end_control_point
108 }
109
110 pub fn end_point(&self) -> &Point {
111 &self.end_point
112 }
113}
114
115#[doc(hidden)]
116pub struct VectorPathCommandCubicBezierCurveBuilder {
117 inner: VectorPathCommandCubicBezierCurve,
118}
119
120#[deprecated]
121pub type RTDVectorPathCommandCubicBezierCurveBuilder = VectorPathCommandCubicBezierCurveBuilder;
122
123impl VectorPathCommandCubicBezierCurveBuilder {
124 pub fn build(&self) -> VectorPathCommandCubicBezierCurve {
125 self.inner.clone()
126 }
127
128 pub fn start_control_point<T: AsRef<Point>>(&mut self, start_control_point: T) -> &mut Self {
129 self.inner.start_control_point = start_control_point.as_ref().clone();
130 self
131 }
132
133 pub fn end_control_point<T: AsRef<Point>>(&mut self, end_control_point: T) -> &mut Self {
134 self.inner.end_control_point = end_control_point.as_ref().clone();
135 self
136 }
137
138 pub fn end_point<T: AsRef<Point>>(&mut self, end_point: T) -> &mut Self {
139 self.inner.end_point = end_point.as_ref().clone();
140 self
141 }
142}
143
144impl AsRef<VectorPathCommandCubicBezierCurve> for VectorPathCommandCubicBezierCurve {
145 fn as_ref(&self) -> &VectorPathCommandCubicBezierCurve {
146 self
147 }
148}
149
150impl AsRef<VectorPathCommandCubicBezierCurve> for VectorPathCommandCubicBezierCurveBuilder {
151 fn as_ref(&self) -> &VectorPathCommandCubicBezierCurve {
152 &self.inner
153 }
154}
155
156#[derive(Debug, Clone, Default, Serialize, Deserialize)]
158pub struct VectorPathCommandLine {
159 #[doc(hidden)]
160 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
161 extra: Option<String>,
162 #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
163 client_id: Option<i32>,
164 end_point: Point,
166}
167
168impl RObject for VectorPathCommandLine {
169 #[doc(hidden)]
170 fn extra(&self) -> Option<&str> {
171 self.extra.as_deref()
172 }
173 #[doc(hidden)]
174 fn client_id(&self) -> Option<i32> {
175 self.client_id
176 }
177}
178
179impl TDVectorPathCommand for VectorPathCommandLine {}
180
181impl VectorPathCommandLine {
182 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
183 Ok(serde_json::from_str(json.as_ref())?)
184 }
185 pub fn builder() -> VectorPathCommandLineBuilder {
186 let mut inner = VectorPathCommandLine::default();
187 inner.extra = Some(Uuid::new_v4().to_string());
188
189 VectorPathCommandLineBuilder { inner }
190 }
191
192 pub fn end_point(&self) -> &Point {
193 &self.end_point
194 }
195}
196
197#[doc(hidden)]
198pub struct VectorPathCommandLineBuilder {
199 inner: VectorPathCommandLine,
200}
201
202#[deprecated]
203pub type RTDVectorPathCommandLineBuilder = VectorPathCommandLineBuilder;
204
205impl VectorPathCommandLineBuilder {
206 pub fn build(&self) -> VectorPathCommandLine {
207 self.inner.clone()
208 }
209
210 pub fn end_point<T: AsRef<Point>>(&mut self, end_point: T) -> &mut Self {
211 self.inner.end_point = end_point.as_ref().clone();
212 self
213 }
214}
215
216impl AsRef<VectorPathCommandLine> for VectorPathCommandLine {
217 fn as_ref(&self) -> &VectorPathCommandLine {
218 self
219 }
220}
221
222impl AsRef<VectorPathCommandLine> for VectorPathCommandLineBuilder {
223 fn as_ref(&self) -> &VectorPathCommandLine {
224 &self.inner
225 }
226}