rust_tdlib/types/
poll_option.rs1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct PollOption {
8 #[doc(hidden)]
9 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
10 extra: Option<String>,
11 #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
12 client_id: Option<i32>,
13 #[serde(default)]
16 text: String,
17 #[serde(default)]
20 voter_count: i32,
21 #[serde(default)]
24 vote_percentage: i32,
25 #[serde(default)]
28 is_chosen: bool,
29 #[serde(default)]
32 is_being_chosen: bool,
33}
34
35impl RObject for PollOption {
36 #[doc(hidden)]
37 fn extra(&self) -> Option<&str> {
38 self.extra.as_deref()
39 }
40 #[doc(hidden)]
41 fn client_id(&self) -> Option<i32> {
42 self.client_id
43 }
44}
45
46impl PollOption {
47 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
48 Ok(serde_json::from_str(json.as_ref())?)
49 }
50 pub fn builder() -> PollOptionBuilder {
51 let mut inner = PollOption::default();
52 inner.extra = Some(Uuid::new_v4().to_string());
53
54 PollOptionBuilder { inner }
55 }
56
57 pub fn text(&self) -> &String {
58 &self.text
59 }
60
61 pub fn voter_count(&self) -> i32 {
62 self.voter_count
63 }
64
65 pub fn vote_percentage(&self) -> i32 {
66 self.vote_percentage
67 }
68
69 pub fn is_chosen(&self) -> bool {
70 self.is_chosen
71 }
72
73 pub fn is_being_chosen(&self) -> bool {
74 self.is_being_chosen
75 }
76}
77
78#[doc(hidden)]
79pub struct PollOptionBuilder {
80 inner: PollOption,
81}
82
83#[deprecated]
84pub type RTDPollOptionBuilder = PollOptionBuilder;
85
86impl PollOptionBuilder {
87 pub fn build(&self) -> PollOption {
88 self.inner.clone()
89 }
90
91 pub fn text<T: AsRef<str>>(&mut self, text: T) -> &mut Self {
92 self.inner.text = text.as_ref().to_string();
93 self
94 }
95
96 pub fn voter_count(&mut self, voter_count: i32) -> &mut Self {
97 self.inner.voter_count = voter_count;
98 self
99 }
100
101 pub fn vote_percentage(&mut self, vote_percentage: i32) -> &mut Self {
102 self.inner.vote_percentage = vote_percentage;
103 self
104 }
105
106 pub fn is_chosen(&mut self, is_chosen: bool) -> &mut Self {
107 self.inner.is_chosen = is_chosen;
108 self
109 }
110
111 pub fn is_being_chosen(&mut self, is_being_chosen: bool) -> &mut Self {
112 self.inner.is_being_chosen = is_being_chosen;
113 self
114 }
115}
116
117impl AsRef<PollOption> for PollOption {
118 fn as_ref(&self) -> &PollOption {
119 self
120 }
121}
122
123impl AsRef<PollOption> for PollOptionBuilder {
124 fn as_ref(&self) -> &PollOption {
125 &self.inner
126 }
127}