Merge pull request #207 from teloxide/tune-markups

Tune markups
This commit is contained in:
Hirrolot 2022-04-24 01:14:06 +06:00 committed by GitHub
commit 896c9991f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 16 deletions

View file

@ -12,6 +12,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Support for Telegram Bot API [version 6.0](https://core.telegram.org/bots/api#april-16-2022)
- Note that some field were renamed
### Changed
- Accept `IntoIterator` in `KeyboardMarkup::append_row`.
- Accept `Into<String>` instead of `String` in `InlineKeyboardButton::{url, callback, switch_inline_query, switch_inline_query_current_chat}`.
## 0.5.1 - 2022-04-18
### Fixed

View file

@ -123,35 +123,50 @@ pub enum InlineKeyboardButtonKind {
/// let url_button = InlineKeyboardButton::url("Text".to_string(), url);
/// ```
impl InlineKeyboardButton {
pub fn url(text: String, url: reqwest::Url) -> InlineKeyboardButton {
pub fn url<T>(text: T, url: reqwest::Url) -> InlineKeyboardButton
where
T: Into<String>,
{
InlineKeyboardButton {
text,
text: text.into(),
kind: InlineKeyboardButtonKind::Url(url),
}
}
pub fn callback(text: String, callback_data: String) -> InlineKeyboardButton {
pub fn callback<T, C>(text: T, callback_data: C) -> InlineKeyboardButton
where
T: Into<String>,
C: Into<String>,
{
InlineKeyboardButton {
text,
kind: InlineKeyboardButtonKind::CallbackData(callback_data),
text: text.into(),
kind: InlineKeyboardButtonKind::CallbackData(callback_data.into()),
}
}
pub fn switch_inline_query(text: String, switch_inline_query: String) -> InlineKeyboardButton {
pub fn switch_inline_query<T, Q>(text: T, switch_inline_query: Q) -> InlineKeyboardButton
where
T: Into<String>,
Q: Into<String>,
{
InlineKeyboardButton {
text,
kind: InlineKeyboardButtonKind::SwitchInlineQuery(switch_inline_query),
text: text.into(),
kind: InlineKeyboardButtonKind::SwitchInlineQuery(switch_inline_query.into()),
}
}
pub fn switch_inline_query_current_chat(
text: String,
switch_inline_query_current_chat: String,
) -> InlineKeyboardButton {
pub fn switch_inline_query_current_chat<T, Q>(
text: T,
switch_inline_query_current_chat: Q,
) -> InlineKeyboardButton
where
T: Into<String>,
Q: Into<String>,
{
InlineKeyboardButton {
text,
text: text.into(),
kind: InlineKeyboardButtonKind::SwitchInlineQueryCurrentChat(
switch_inline_query_current_chat,
switch_inline_query_current_chat.into(),
),
}
}

View file

@ -67,8 +67,11 @@ impl KeyboardMarkup {
}
}
pub fn append_row(mut self, buttons: Vec<KeyboardButton>) -> Self {
self.keyboard.push(buttons);
pub fn append_row<R>(mut self, buttons: R) -> Self
where
R: IntoIterator<Item = KeyboardButton>,
{
self.keyboard.push(buttons.into_iter().collect());
self
}