1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
use super::{inline, reply, ForceReply};
use serde::Serialize;

/// An enum of possible keyboards.
#[derive(Serialize, Debug, PartialEq, Eq, Clone, Copy, Hash)]
#[serde(untagged)]
// todo: #[non_exhaustive]
pub enum Any<'a> {
    /// An inline keyboard.
    Inline(inline::Keyboard<'a>),
    /// A reply markup.
    Reply(reply::Keyboard<'a>),
    /// Removes reply markup.
    RemoveReply(reply::Remove),
    /// Forces reply.
    ForceReply(ForceReply),
}

impl Any<'_> {
    /// Checks if `self` is `Inline`.
    pub fn is_inline(&self) -> bool {
        match self {
            Any::Inline(..) => true,
            _ => false,
        }
    }

    /// Checks if `self` is `Reply`.
    pub fn is_reply(&self) -> bool {
        match self {
            Any::Reply(..) => true,
            _ => false,
        }
    }

    /// Checks if `self` is `RemoveReply`.
    pub fn is_remove_reply(&self) -> bool {
        match self {
            Any::RemoveReply(..) => true,
            _ => false,
        }
    }

    /// Checks if `self` is `ForceReply`.
    pub fn is_force_reply(&self) -> bool {
        match self {
            Any::ForceReply(..) => true,
            _ => false,
        }
    }
}

impl<'a> From<inline::Keyboard<'a>> for Any<'a> {
    fn from(keyboard: inline::Keyboard<'a>) -> Self {
        Any::Inline(keyboard)
    }
}

impl<'a> From<inline::Markup<'a>> for Any<'a> {
    fn from(keyboard: inline::Markup<'a>) -> Self {
        Any::Inline(keyboard.into())
    }
}

impl<'a> From<reply::Keyboard<'a>> for Any<'a> {
    fn from(keyboard: reply::Keyboard<'a>) -> Self {
        Any::Reply(keyboard)
    }
}

impl<'a> From<reply::Markup<'a>> for Any<'a> {
    fn from(keyboard: reply::Markup<'a>) -> Self {
        Any::Reply(keyboard.into())
    }
}

impl<'a> From<reply::Remove> for Any<'a> {
    fn from(keyboard: reply::Remove) -> Self {
        Any::RemoveReply(keyboard)
    }
}

impl<'a> From<ForceReply> for Any<'a> {
    fn from(keyboard: ForceReply) -> Self {
        Any::ForceReply(keyboard)
    }
}