From dad067da447f121df1392fe6032b0829380abfea Mon Sep 17 00:00:00 2001 From: Ali Date: Thu, 3 Oct 2024 12:35:53 +0330 Subject: [PATCH 1/3] removing useless Generic T on `selective`, adding tests --- .../src/types/reply_keyboard_markup.rs | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/crates/teloxide-core/src/types/reply_keyboard_markup.rs b/crates/teloxide-core/src/types/reply_keyboard_markup.rs index 4b38b2df..1c9c5935 100644 --- a/crates/teloxide-core/src/types/reply_keyboard_markup.rs +++ b/crates/teloxide-core/src/types/reply_keyboard_markup.rs @@ -125,7 +125,7 @@ impl KeyboardMarkup { /// Sets [`selective`] to `true`. /// /// [`selective`]: KeyboardMarkup::selective - pub fn selective(self) -> Self { + pub fn selective(self) -> Self { Self { selective: true, ..self } } } @@ -146,6 +146,26 @@ mod tests { "selective": false } "#; - serde_json::from_str::(data).unwrap(); + assert!(serde_json::from_str::(data).is_ok()) + } + #[test] + fn serialize() { + let keyboard = vec![ + vec![ + KeyboardButton::new("a"), + KeyboardButton::new("b"), + KeyboardButton::new("c"), + KeyboardButton::new("d"), + ] + ]; + let keyboard_markup = KeyboardMarkup::new(keyboard) + .persistent() + .resize_keyboard() + .selective() + .one_time_keyboard(); + let expected = r#"{"keyboard":[[{"text":"a"},{"text":"b"},{"text":"c"},{"text":"d"}]],"is_persistent":true,"resize_keyboard":true,"one_time_keyboard":true,"selective":true}"#; + + assert!(serde_json::ser::to_string(&keyboard_markup).is_ok_and(|s|s.eq(expected))); + } } From 0f4ee3023a7a0ace8497f9bec5db5a5cd6500bb9 Mon Sep 17 00:00:00 2001 From: Ali Date: Thu, 3 Oct 2024 12:36:15 +0330 Subject: [PATCH 2/3] fmt --- .../src/types/reply_keyboard_markup.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/crates/teloxide-core/src/types/reply_keyboard_markup.rs b/crates/teloxide-core/src/types/reply_keyboard_markup.rs index 1c9c5935..57da3f25 100644 --- a/crates/teloxide-core/src/types/reply_keyboard_markup.rs +++ b/crates/teloxide-core/src/types/reply_keyboard_markup.rs @@ -150,14 +150,12 @@ mod tests { } #[test] fn serialize() { - let keyboard = vec![ - vec![ - KeyboardButton::new("a"), - KeyboardButton::new("b"), - KeyboardButton::new("c"), - KeyboardButton::new("d"), - ] - ]; + let keyboard = vec![vec![ + KeyboardButton::new("a"), + KeyboardButton::new("b"), + KeyboardButton::new("c"), + KeyboardButton::new("d"), + ]]; let keyboard_markup = KeyboardMarkup::new(keyboard) .persistent() .resize_keyboard() @@ -165,7 +163,6 @@ mod tests { .one_time_keyboard(); let expected = r#"{"keyboard":[[{"text":"a"},{"text":"b"},{"text":"c"},{"text":"d"}]],"is_persistent":true,"resize_keyboard":true,"one_time_keyboard":true,"selective":true}"#; - assert!(serde_json::ser::to_string(&keyboard_markup).is_ok_and(|s|s.eq(expected))); - + assert!(serde_json::ser::to_string(&keyboard_markup).is_ok_and(|s| s.eq(expected))); } } From ebe89a637a669973eeaa2031b5021cddee40e130 Mon Sep 17 00:00:00 2001 From: Lewis Pearson Date: Sat, 5 Oct 2024 18:15:42 -0400 Subject: [PATCH 3/3] Update the `teloxide-core` changelog --- crates/teloxide-core/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/teloxide-core/CHANGELOG.md b/crates/teloxide-core/CHANGELOG.md index 9a856377..54916b3c 100644 --- a/crates/teloxide-core/CHANGELOG.md +++ b/crates/teloxide-core/CHANGELOG.md @@ -65,11 +65,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Wrap `Public` variant of `ChatKind` in `Box` - Replaced `user_ids` with `users` in `UsersShared` struct +- Remove a useless generic type in the `KeyboardMarkup::selective` function ([#1176][pr1176]) + [pr1131]: https://github.com/teloxide/teloxide/pull/1131 [pr1134]: https://github.com/teloxide/teloxide/pull/1134 [pr1146]: https://github.com/teloxide/teloxide/pull/1146 [pr1147]: https://github.com/teloxide/teloxide/pull/1147 [pr1151]: https://github.com/teloxide/teloxide/pull/1151 +[pr1176]: https://github.com/teloxide/teloxide/pull/1176 ### Removed