From 8eda6cd853c52b19387798dd54b17fd33c646a4e Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Mon, 13 Feb 2023 22:10:06 +0400 Subject: [PATCH] Simplify some code using struct-update-syntax --- crates/teloxide-core/src/types/force_reply.rs | 10 +++----- .../src/types/reply_keyboard_markup.rs | 25 ++++++++----------- .../src/types/reply_keyboard_remove.rs | 5 ++-- 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/crates/teloxide-core/src/types/force_reply.rs b/crates/teloxide-core/src/types/force_reply.rs index 03c0439b..79a42e4e 100644 --- a/crates/teloxide-core/src/types/force_reply.rs +++ b/crates/teloxide-core/src/types/force_reply.rs @@ -39,20 +39,18 @@ impl ForceReply { Self { force_reply: True, input_field_placeholder: None, selective: false } } - pub fn input_field_placeholder(mut self, val: T) -> Self + pub fn input_field_placeholder(self, val: T) -> Self where T: Into>, { - self.input_field_placeholder = val.into(); - self + Self { input_field_placeholder: val.into(), ..self } } /// Sets [`selective`] to `true`. /// /// [`selective`]: ForceReply::selective #[must_use] - pub const fn selective(mut self) -> Self { - self.selective = true; - self + pub fn selective(self) -> Self { + Self { selective: true, ..self } } } diff --git a/crates/teloxide-core/src/types/reply_keyboard_markup.rs b/crates/teloxide-core/src/types/reply_keyboard_markup.rs index 8d5431c7..19199a3d 100644 --- a/crates/teloxide-core/src/types/reply_keyboard_markup.rs +++ b/crates/teloxide-core/src/types/reply_keyboard_markup.rs @@ -95,41 +95,36 @@ impl KeyboardMarkup { /// Sets [`is_persistent`] to `true`. /// /// [`is_persistent`]: KeyboardMarkup::is_persistent - pub fn persistent(mut self) -> Self { - self.is_persistent = true; - self + pub fn persistent(self) -> Self { + Self { is_persistent: true, ..self } } /// Sets [`resize_keyboard`] to `true`. /// /// [`resize_keyboard`]: KeyboardMarkup::resize_keyboard - pub fn resize_keyboard(mut self) -> Self { - self.resize_keyboard = true; - self + pub fn resize_keyboard(self) -> Self { + Self { resize_keyboard: true, ..self } } /// Sets [`one_time_keyboard`] to `true`. /// /// [`one_time_keyboard`]: KeyboardMarkup::one_time_keyboard - pub fn one_time_keyboard(mut self) -> Self { - self.one_time_keyboard = true; - self + pub fn one_time_keyboard(self) -> Self { + Self { one_time_keyboard: true, ..self } } // FIXME: document + remove Option from signature. - pub fn input_field_placeholder(mut self, val: T) -> Self + pub fn input_field_placeholder(self, val: T) -> Self where T: Into>, { - self.input_field_placeholder = val.into(); - self + Self { input_field_placeholder: val.into(), ..self } } /// Sets [`selective`] to `true`. /// /// [`selective`]: KeyboardMarkup::selective - pub fn selective(mut self) -> Self { - self.selective = true; - self + pub fn selective(self) -> Self { + Self { selective: true, ..self } } } diff --git a/crates/teloxide-core/src/types/reply_keyboard_remove.rs b/crates/teloxide-core/src/types/reply_keyboard_remove.rs index 296abc52..636f1618 100644 --- a/crates/teloxide-core/src/types/reply_keyboard_remove.rs +++ b/crates/teloxide-core/src/types/reply_keyboard_remove.rs @@ -48,8 +48,7 @@ impl KeyboardRemove { /// /// [`selective`]: KeyboardRemove::selective #[must_use] - pub const fn selective(mut self) -> Self { - self.selective = true; - self + pub const fn selective(self) -> Self { + Self { selective: true, ..self } } }