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
use super::{Animation, Audio, Document, Photo, Video};
use is_macro::Is;
use serde::Serialize;

/// Represents media that can be used to edit a message.
#[derive(Debug, PartialEq, Eq, Clone, Hash, Serialize, Is)]
#[serde(untagged)]
#[non_exhaustive]
#[must_use]
pub enum EditableMedia {
    /// An animation that will replace the old media.
    Animation(Animation),
    /// An audio that will replace the old media.
    Audio(Audio),
    /// A document that will replace the old media.
    Document(Document),
    /// A photo that will replace the old media.
    Photo(Photo),
    /// A video that will replace the old media.
    Video(Video),
}

impl EditableMedia {
    pub(crate) const fn name(&self) -> &'static str {
        match self {
            Self::Animation(..) => "animation",
            Self::Audio(..) => "audio",
            Self::Document(..) => "document",
            Self::Photo(..) => "photo",
            Self::Video(..) => "video",
        }
    }
}

impl From<Animation> for EditableMedia {
    fn from(animation: Animation) -> Self {
        Self::Animation(animation)
    }
}

impl From<Audio> for EditableMedia {
    fn from(audio: Audio) -> Self {
        Self::Audio(audio)
    }
}

impl From<Document> for EditableMedia {
    fn from(document: Document) -> Self {
        Self::Document(document)
    }
}

impl From<Photo> for EditableMedia {
    fn from(photo: Photo) -> Self {
        Self::Photo(photo)
    }
}

impl From<Video> for EditableMedia {
    fn from(video: Video) -> Self {
        Self::Video(video)
    }
}