Add setters to Poll

This commit is contained in:
Temirkhan Myrzamadi 2020-07-28 16:11:58 +06:00
parent e593d4c1c7
commit 6e7257cb5c

View file

@ -39,6 +39,93 @@ pub struct Poll {
pub correct_option_id: Option<i32>,
}
impl Poll {
#[allow(clippy::too_many_arguments)]
pub fn new<S1, S2, O>(
id: S1,
question: S2,
options: O,
is_closed: bool,
total_voter_count: i32,
is_anonymous: bool,
poll_type: PollType,
allows_multiple_answers: bool,
) -> Self
where
S1: Into<String>,
S2: Into<String>,
O: Into<Vec<PollOption>>,
{
Self {
id: id.into(),
question: question.into(),
options: options.into(),
is_closed,
total_voter_count,
is_anonymous,
poll_type,
allows_multiple_answers,
correct_option_id: None,
}
}
pub fn id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.id = val.into();
self
}
pub fn question<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.question = val.into();
self
}
pub fn options<P>(mut self, val: P) -> Self
where
P: Into<Vec<PollOption>>,
{
self.options = val.into();
self
}
#[allow(clippy::wrong_self_convention)]
pub fn is_closed(mut self, val: bool) -> Self {
self.is_closed = val;
self
}
pub fn total_voter_count(mut self, val: i32) -> Self {
self.total_voter_count = val;
self
}
#[allow(clippy::wrong_self_convention)]
pub fn is_anonymous(mut self, val: bool) -> Self {
self.is_anonymous = val;
self
}
pub fn poll_type(mut self, val: PollType) -> Self {
self.poll_type = val;
self
}
pub fn allows_multiple_answers(mut self, val: bool) -> Self {
self.allows_multiple_answers = val;
self
}
pub fn correct_option_id(mut self, val: i32) -> Self {
self.correct_option_id = Some(val);
self
}
}
/// This object contains information about one answer option in a poll.
///
/// [The official docs](https://core.telegram.org/bots/api#polloption).