derive_more

This commit is contained in:
p0lunin 2020-01-10 12:24:31 +02:00
parent c7fb8da774
commit 1a8f012de4

View file

@ -1,10 +1,11 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use derive_more::From;
use crate::types::{ use crate::types::{
ForceReply, InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply, InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove,
}; };
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, From)]
#[serde(untagged)] #[serde(untagged)]
pub enum ReplyMarkup { pub enum ReplyMarkup {
InlineKeyboardMarkup(InlineKeyboardMarkup), InlineKeyboardMarkup(InlineKeyboardMarkup),
@ -13,26 +14,15 @@ pub enum ReplyMarkup {
ForceReply(ForceReply), ForceReply(ForceReply),
} }
impl From<InlineKeyboardMarkup> for ReplyMarkup { #[cfg(test)]
fn from(markup: InlineKeyboardMarkup) -> Self { mod tests {
ReplyMarkup::InlineKeyboardMarkup(markup) use super::*;
}
}
impl From<ForceReply> for ReplyMarkup { #[test]
fn from(markup: ForceReply) -> Self { fn inline_keyboard_markup() {
ReplyMarkup::ForceReply(markup) let data = InlineKeyboardMarkup::new();
let expected = ReplyMarkup::InlineKeyboardMarkup(data.clone());
let actual: ReplyMarkup = data.into();
assert_eq!(actual, expected)
} }
} }
impl From<ReplyKeyboardMarkup> for ReplyMarkup {
fn from(markup: ReplyKeyboardMarkup) -> Self {
ReplyMarkup::ReplyKeyboardMarkup(markup)
}
}
impl From<ReplyKeyboardRemove> for ReplyMarkup {
fn from(markup: ReplyKeyboardRemove) -> Self {
ReplyMarkup::ReplyKeyboardRemove(markup)
}
}