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
use super::InputFile;
use serde::{Serialize, Serializer};

/// Represents a chat photo to be set.
///
/// Note that a chat photo cannot be set via either a file ID or a URL.
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
#[must_use]
pub struct ChatPhoto(pub(crate) InputFile);

impl ChatPhoto {
    /// Constructs a `ChatPhoto`.
    pub fn with_bytes(bytes: impl Into<Vec<u8>>) -> Self {
        let file = InputFile::File {
            filename: "photo.jpg".into(),
            bytes: bytes.into(),
        };

        Self(file)
    }
}

impl Serialize for ChatPhoto {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
    {
        self.0.serialize(serializer, "photo")
    }
}