Simplify some code using struct-update-syntax

This commit is contained in:
Maybe Waffle 2023-02-13 22:10:06 +04:00
parent 2a8f550b66
commit 8eda6cd853
3 changed files with 16 additions and 24 deletions

View file

@ -39,20 +39,18 @@ impl ForceReply {
Self { force_reply: True, input_field_placeholder: None, selective: false } Self { force_reply: True, input_field_placeholder: None, selective: false }
} }
pub fn input_field_placeholder<T>(mut self, val: T) -> Self pub fn input_field_placeholder<T>(self, val: T) -> Self
where where
T: Into<Option<String>>, T: Into<Option<String>>,
{ {
self.input_field_placeholder = val.into(); Self { input_field_placeholder: val.into(), ..self }
self
} }
/// Sets [`selective`] to `true`. /// Sets [`selective`] to `true`.
/// ///
/// [`selective`]: ForceReply::selective /// [`selective`]: ForceReply::selective
#[must_use] #[must_use]
pub const fn selective(mut self) -> Self { pub fn selective(self) -> Self {
self.selective = true; Self { selective: true, ..self }
self
} }
} }

View file

@ -95,41 +95,36 @@ impl KeyboardMarkup {
/// Sets [`is_persistent`] to `true`. /// Sets [`is_persistent`] to `true`.
/// ///
/// [`is_persistent`]: KeyboardMarkup::is_persistent /// [`is_persistent`]: KeyboardMarkup::is_persistent
pub fn persistent(mut self) -> Self { pub fn persistent(self) -> Self {
self.is_persistent = true; Self { is_persistent: true, ..self }
self
} }
/// Sets [`resize_keyboard`] to `true`. /// Sets [`resize_keyboard`] to `true`.
/// ///
/// [`resize_keyboard`]: KeyboardMarkup::resize_keyboard /// [`resize_keyboard`]: KeyboardMarkup::resize_keyboard
pub fn resize_keyboard(mut self) -> Self { pub fn resize_keyboard(self) -> Self {
self.resize_keyboard = true; Self { resize_keyboard: true, ..self }
self
} }
/// Sets [`one_time_keyboard`] to `true`. /// Sets [`one_time_keyboard`] to `true`.
/// ///
/// [`one_time_keyboard`]: KeyboardMarkup::one_time_keyboard /// [`one_time_keyboard`]: KeyboardMarkup::one_time_keyboard
pub fn one_time_keyboard(mut self) -> Self { pub fn one_time_keyboard(self) -> Self {
self.one_time_keyboard = true; Self { one_time_keyboard: true, ..self }
self
} }
// FIXME: document + remove Option from signature. // FIXME: document + remove Option from signature.
pub fn input_field_placeholder<T>(mut self, val: T) -> Self pub fn input_field_placeholder<T>(self, val: T) -> Self
where where
T: Into<Option<String>>, T: Into<Option<String>>,
{ {
self.input_field_placeholder = val.into(); Self { input_field_placeholder: val.into(), ..self }
self
} }
/// Sets [`selective`] to `true`. /// Sets [`selective`] to `true`.
/// ///
/// [`selective`]: KeyboardMarkup::selective /// [`selective`]: KeyboardMarkup::selective
pub fn selective<T>(mut self) -> Self { pub fn selective<T>(self) -> Self {
self.selective = true; Self { selective: true, ..self }
self
} }
} }

View file

@ -48,8 +48,7 @@ impl KeyboardRemove {
/// ///
/// [`selective`]: KeyboardRemove::selective /// [`selective`]: KeyboardRemove::selective
#[must_use] #[must_use]
pub const fn selective(mut self) -> Self { pub const fn selective(self) -> Self {
self.selective = true; Self { selective: true, ..self }
self
} }
} }