From c2fb9377638bf8b4f2d426b45e6f590efafd5308 Mon Sep 17 00:00:00 2001 From: p0lunin Date: Thu, 9 Jan 2020 20:59:59 +0200 Subject: [PATCH 1/4] rename variants ReplyMarkup --- src/types/reply_markup.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/types/reply_markup.rs b/src/types/reply_markup.rs index aa21a7ba..00e3decf 100644 --- a/src/types/reply_markup.rs +++ b/src/types/reply_markup.rs @@ -7,8 +7,8 @@ use crate::types::{ #[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] #[serde(untagged)] pub enum ReplyMarkup { - Inline(InlineKeyboardMarkup), - Reply(ReplyKeyboardMarkup), + InlineKeyboardMarkup(InlineKeyboardMarkup), + ReplyKeyboardMarkup(ReplyKeyboardMarkup), ReplyKeyboardRemove(ReplyKeyboardRemove), ForceReply(ForceReply), } From afa877ff5620a087c48d7367d5a9ccb530b4a673 Mon Sep 17 00:00:00 2001 From: p0lunin Date: Thu, 9 Jan 2020 21:00:25 +0200 Subject: [PATCH 2/4] add implementation From for ReplyMarkup --- src/types/reply_markup.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/types/reply_markup.rs b/src/types/reply_markup.rs index 00e3decf..66546a5e 100644 --- a/src/types/reply_markup.rs +++ b/src/types/reply_markup.rs @@ -12,3 +12,27 @@ pub enum ReplyMarkup { ReplyKeyboardRemove(ReplyKeyboardRemove), ForceReply(ForceReply), } + +impl From for ReplyMarkup { + fn from(markup: InlineKeyboardMarkup) -> Self { + ReplyMarkup::Inline(markup) + } +} + +impl From for ReplyMarkup { + fn from(markup: ForceReply) -> Self { + ReplyMarkup::ForceReply(markup) + } +} + +impl From for ReplyMarkup { + fn from(markup: ReplyKeyboardMarkup) -> Self { + ReplyMarkup::ReplyKeyboardMarkup(markup) + } +} + +impl From for ReplyMarkup { + fn from(markup: ReplyKeyboardRemove) -> Self { + ReplyMarkup::ReplyKeyboardRemove(markup) + } +} From c7fb8da77492b96fdbec1f25f790caf73decf303 Mon Sep 17 00:00:00 2001 From: p0lunin Date: Thu, 9 Jan 2020 21:04:05 +0200 Subject: [PATCH 3/4] fix wrong name --- src/types/reply_markup.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/reply_markup.rs b/src/types/reply_markup.rs index 66546a5e..cf95bad6 100644 --- a/src/types/reply_markup.rs +++ b/src/types/reply_markup.rs @@ -15,7 +15,7 @@ pub enum ReplyMarkup { impl From for ReplyMarkup { fn from(markup: InlineKeyboardMarkup) -> Self { - ReplyMarkup::Inline(markup) + ReplyMarkup::InlineKeyboardMarkup(markup) } } From 1a8f012de46ec4ee78eec44f9f431090fe3eb1df Mon Sep 17 00:00:00 2001 From: p0lunin Date: Fri, 10 Jan 2020 12:24:31 +0200 Subject: [PATCH 4/4] derive_more --- src/types/reply_markup.rs | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/src/types/reply_markup.rs b/src/types/reply_markup.rs index cf95bad6..87845395 100644 --- a/src/types/reply_markup.rs +++ b/src/types/reply_markup.rs @@ -1,10 +1,11 @@ use serde::{Deserialize, Serialize}; +use derive_more::From; use crate::types::{ ForceReply, InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, }; -#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, From)] #[serde(untagged)] pub enum ReplyMarkup { InlineKeyboardMarkup(InlineKeyboardMarkup), @@ -13,26 +14,15 @@ pub enum ReplyMarkup { ForceReply(ForceReply), } -impl From for ReplyMarkup { - fn from(markup: InlineKeyboardMarkup) -> Self { - ReplyMarkup::InlineKeyboardMarkup(markup) - } -} +#[cfg(test)] +mod tests { + use super::*; -impl From for ReplyMarkup { - fn from(markup: ForceReply) -> Self { - ReplyMarkup::ForceReply(markup) + #[test] + fn inline_keyboard_markup() { + let data = InlineKeyboardMarkup::new(); + let expected = ReplyMarkup::InlineKeyboardMarkup(data.clone()); + let actual: ReplyMarkup = data.into(); + assert_eq!(actual, expected) } -} - -impl From for ReplyMarkup { - fn from(markup: ReplyKeyboardMarkup) -> Self { - ReplyMarkup::ReplyKeyboardMarkup(markup) - } -} - -impl From for ReplyMarkup { - fn from(markup: ReplyKeyboardRemove) -> Self { - ReplyMarkup::ReplyKeyboardRemove(markup) - } -} +} \ No newline at end of file