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