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
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
use super::{Animation, Audio, Document, Photo, Video};
use serde::Serialize;

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

impl EditableMedia<'_> {
    pub(crate) fn name(&self) -> &'static str {
        match self {
            EditableMedia::Animation(..) => "animation",
            EditableMedia::Audio(..) => "audio",
            EditableMedia::Document(..) => "document",
            EditableMedia::Photo(..) => "photo",
            EditableMedia::Video(..) => "video",
        }
    }
    /// Checks if `self` is `Animation`.
    pub fn is_animation(&self) -> bool {
        match self {
            EditableMedia::Animation(..) => true,
            _ => false,
        }
    }

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

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

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

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

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

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

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

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

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