diff --git a/crates/teloxide-core/CHANGELOG.md b/crates/teloxide-core/CHANGELOG.md index 280f96a1..d6f61e34 100644 --- a/crates/teloxide-core/CHANGELOG.md +++ b/crates/teloxide-core/CHANGELOG.md @@ -16,6 +16,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [pr851]: https://github.com/teloxide/teloxide/pull/851 +### Changed + +- Types of `Option` fields of `KeyboardMarkup`, `KeyboardRemove` and `ForceReply` to `bool` ([#853][pr853]) +- Type of `KeyboardMarkup::input_field_placeholder`: `Option` => `String` ([#853][pr853]) + +[pr852]: https://github.com/teloxide/teloxide/pull/853 + ### Deprecated - `Update::user`, use `Update::from` instead ([#850][pr850]) diff --git a/crates/teloxide-core/src/types/force_reply.rs b/crates/teloxide-core/src/types/force_reply.rs index f92d8d1c..79a42e4e 100644 --- a/crates/teloxide-core/src/types/force_reply.rs +++ b/crates/teloxide-core/src/types/force_reply.rs @@ -29,26 +29,28 @@ pub struct ForceReply { /// (has reply_to_message_id), sender of the original message. /// /// [`Message`]: crate::types::Message - pub selective: Option, + #[serde(skip_serializing_if = "std::ops::Not::not")] + pub selective: bool, } impl ForceReply { #[must_use] pub const fn new() -> Self { - Self { force_reply: True, input_field_placeholder: None, selective: None } + 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, val: bool) -> Self { - self.selective = Some(val); - 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 37ba29bb..7ea99f7c 100644 --- a/crates/teloxide-core/src/types/reply_keyboard_markup.rs +++ b/crates/teloxide-core/src/types/reply_keyboard_markup.rs @@ -1,3 +1,4 @@ +// FIXME: rename module (s/reply_//) use serde::{Deserialize, Serialize}; use crate::types::KeyboardButton; @@ -11,7 +12,6 @@ use crate::types::KeyboardButton; /// [Introduction to bots]: https://core.telegram.org/bots#keyboards #[serde_with_macros::skip_serializing_none] #[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, Default)] -// FIXME: unoption bools? pub struct KeyboardMarkup { /// Array of button rows, each represented by an Array of /// [`KeyboardButton`] objects @@ -29,18 +29,21 @@ pub struct KeyboardMarkup { /// (e.g., make the keyboard smaller if there are just two rows of /// buttons). Defaults to `false`, in which case the custom keyboard is /// always of the same height as the app's standard keyboard. - pub resize_keyboard: Option, + #[serde(skip_serializing_if = "std::ops::Not::not")] + pub resize_keyboard: bool, /// Requests clients to hide the keyboard as soon as it's been used. The /// keyboard will still be available, but clients will automatically /// display the usual letter-keyboard in the chat – the user can press a /// special button in the input field to see the custom keyboard again. /// Defaults to `false`. - pub one_time_keyboard: Option, + #[serde(skip_serializing_if = "std::ops::Not::not")] + pub one_time_keyboard: bool, /// The placeholder to be shown in the input field when the keyboard is /// active; 1-64 characters. - pub input_field_placeholder: Option, + #[serde(skip_serializing_if = "str::is_empty")] + pub input_field_placeholder: String, /// Use this parameter if you want to show the keyboard to specific users /// only. Targets: 1) users that are `@mentioned` in the `text` of the @@ -52,10 +55,12 @@ pub struct KeyboardMarkup { /// in the group don’t see the keyboard. /// /// [`Message`]: crate::types::Message - pub selective: Option, + #[serde(skip_serializing_if = "std::ops::Not::not")] + pub selective: bool, } impl KeyboardMarkup { + // FIXME: Re-think the interface of building keyboard markups pub fn new(keyboard: K) -> Self where K: IntoIterator, @@ -64,10 +69,10 @@ impl KeyboardMarkup { Self { keyboard: keyboard.into_iter().map(<_>::into_iter).map(<_>::collect).collect(), is_persistent: false, - resize_keyboard: None, - one_time_keyboard: None, - input_field_placeholder: None, - selective: None, + resize_keyboard: false, + one_time_keyboard: false, + input_field_placeholder: String::new(), + selective: false, } } @@ -91,40 +96,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 } } - pub fn resize_keyboard(mut self, val: T) -> Self - where - T: Into>, - { - self.resize_keyboard = val.into(); - self + /// Sets [`resize_keyboard`] to `true`. + /// + /// [`resize_keyboard`]: KeyboardMarkup::resize_keyboard + pub fn resize_keyboard(self) -> Self { + Self { resize_keyboard: true, ..self } } - pub fn one_time_keyboard(mut self, val: T) -> Self - where - T: Into>, - { - self.one_time_keyboard = val.into(); - self + /// Sets [`one_time_keyboard`] to `true`. + /// + /// [`one_time_keyboard`]: KeyboardMarkup::one_time_keyboard + pub fn one_time_keyboard(self) -> Self { + Self { one_time_keyboard: true, ..self } } - pub fn input_field_placeholder(mut self, val: T) -> Self + // FIXME: document + pub fn input_field_placeholder(self, val: T) -> Self where - T: Into>, + T: Into, { - self.input_field_placeholder = val.into(); - self + Self { input_field_placeholder: val.into(), ..self } } - pub fn selective(mut self, val: T) -> Self - where - T: Into>, - { - self.selective = val.into(); - self + /// Sets [`selective`] to `true`. + /// + /// [`selective`]: KeyboardMarkup::selective + 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 0f48434b..636f1618 100644 --- a/crates/teloxide-core/src/types/reply_keyboard_remove.rs +++ b/crates/teloxide-core/src/types/reply_keyboard_remove.rs @@ -34,18 +34,21 @@ pub struct KeyboardRemove { /// showing the keyboard with poll options to users who haven't voted yet. /// /// [`Message`]: crate::types::Message - pub selective: Option, + #[serde(skip_serializing_if = "std::ops::Not::not")] + pub selective: bool, } impl KeyboardRemove { #[must_use] pub const fn new() -> Self { - Self { remove_keyboard: True, selective: None } + Self { remove_keyboard: True, selective: false } } + /// Sets [`selective`] to `true`. + /// + /// [`selective`]: KeyboardRemove::selective #[must_use] - pub const fn selective(mut self, val: bool) -> Self { - self.selective = Some(val); - self + pub const fn selective(self) -> Self { + Self { selective: true, ..self } } }