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
use crate::types::*;
use crate::errors::*;
use uuid::Uuid;
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct Poll {
#[doc(hidden)]
#[serde(rename(serialize = "@type", deserialize = "@type"))]
td_name: String,
#[doc(hidden)]
#[serde(rename(serialize = "@extra", deserialize = "@extra"))]
extra: Option<String>,
#[serde(deserialize_with = "serde_aux::field_attributes::deserialize_number_from_string")] id: isize,
question: String,
options: Vec<PollOption>,
total_voter_count: i64,
is_closed: bool,
}
impl RObject for Poll {
#[doc(hidden)] fn td_name(&self) -> &'static str { "poll" }
#[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
}
impl Poll {
pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
pub fn builder() -> RTDPollBuilder {
let mut inner = Poll::default();
inner.td_name = "poll".to_string();
inner.extra = Some(Uuid::new_v4().to_string());
RTDPollBuilder { inner }
}
pub fn id(&self) -> isize { self.id }
pub fn question(&self) -> &String { &self.question }
pub fn options(&self) -> &Vec<PollOption> { &self.options }
pub fn total_voter_count(&self) -> i64 { self.total_voter_count }
pub fn is_closed(&self) -> bool { self.is_closed }
}
#[doc(hidden)]
pub struct RTDPollBuilder {
inner: Poll
}
impl RTDPollBuilder {
pub fn build(&self) -> Poll { self.inner.clone() }
pub fn id(&mut self, id: isize) -> &mut Self {
self.inner.id = id;
self
}
pub fn question<T: AsRef<str>>(&mut self, question: T) -> &mut Self {
self.inner.question = question.as_ref().to_string();
self
}
pub fn options(&mut self, options: Vec<PollOption>) -> &mut Self {
self.inner.options = options;
self
}
pub fn total_voter_count(&mut self, total_voter_count: i64) -> &mut Self {
self.inner.total_voter_count = total_voter_count;
self
}
pub fn is_closed(&mut self, is_closed: bool) -> &mut Self {
self.inner.is_closed = is_closed;
self
}
}
impl AsRef<Poll> for Poll {
fn as_ref(&self) -> &Poll { self }
}
impl AsRef<Poll> for RTDPollBuilder {
fn as_ref(&self) -> &Poll { &self.inner }
}