rust_tdlib/types/
profile_photo.rs

1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5/// Describes a user profile photo
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct ProfilePhoto {
8    #[doc(hidden)]
9    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
10    extra: Option<String>,
11    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
12    client_id: Option<i32>,
13    /// Photo identifier; 0 for an empty photo. Can be used to find a photo in a list of user profile photos
14
15    #[serde(
16        deserialize_with = "super::_common::number_from_string",
17        serialize_with = "super::_common::string_to_number"
18    )]
19    #[serde(default)]
20    id: i64,
21    /// A small (160x160) user profile photo. The file can be downloaded only before the photo is changed
22    small: File,
23    /// A big (640x640) user profile photo. The file can be downloaded only before the photo is changed
24    big: File,
25    /// User profile photo minithumbnail; may be null
26    minithumbnail: Option<Minithumbnail>,
27    /// True, if the photo has animated variant
28
29    #[serde(default)]
30    has_animation: Option<bool>,
31}
32
33impl RObject for ProfilePhoto {
34    #[doc(hidden)]
35    fn extra(&self) -> Option<&str> {
36        self.extra.as_deref()
37    }
38    #[doc(hidden)]
39    fn client_id(&self) -> Option<i32> {
40        self.client_id
41    }
42}
43
44impl ProfilePhoto {
45    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
46        Ok(serde_json::from_str(json.as_ref())?)
47    }
48    pub fn builder() -> ProfilePhotoBuilder {
49        let mut inner = ProfilePhoto::default();
50        inner.extra = Some(Uuid::new_v4().to_string());
51
52        ProfilePhotoBuilder { inner }
53    }
54
55    pub fn id(&self) -> i64 {
56        self.id
57    }
58
59    pub fn small(&self) -> &File {
60        &self.small
61    }
62
63    pub fn big(&self) -> &File {
64        &self.big
65    }
66
67    pub fn minithumbnail(&self) -> &Option<Minithumbnail> {
68        &self.minithumbnail
69    }
70
71    pub fn has_animation(&self) -> &Option<bool> {
72        &self.has_animation
73    }
74}
75
76#[doc(hidden)]
77pub struct ProfilePhotoBuilder {
78    inner: ProfilePhoto,
79}
80
81#[deprecated]
82pub type RTDProfilePhotoBuilder = ProfilePhotoBuilder;
83
84impl ProfilePhotoBuilder {
85    pub fn build(&self) -> ProfilePhoto {
86        self.inner.clone()
87    }
88
89    pub fn id(&mut self, id: i64) -> &mut Self {
90        self.inner.id = id;
91        self
92    }
93
94    pub fn small<T: AsRef<File>>(&mut self, small: T) -> &mut Self {
95        self.inner.small = small.as_ref().clone();
96        self
97    }
98
99    pub fn big<T: AsRef<File>>(&mut self, big: T) -> &mut Self {
100        self.inner.big = big.as_ref().clone();
101        self
102    }
103
104    pub fn minithumbnail<T: AsRef<Minithumbnail>>(&mut self, minithumbnail: T) -> &mut Self {
105        self.inner.minithumbnail = Some(minithumbnail.as_ref().clone());
106        self
107    }
108
109    pub fn has_animation(&mut self, has_animation: bool) -> &mut Self {
110        self.inner.has_animation = Some(has_animation);
111        self
112    }
113}
114
115impl AsRef<ProfilePhoto> for ProfilePhoto {
116    fn as_ref(&self) -> &ProfilePhoto {
117        self
118    }
119}
120
121impl AsRef<ProfilePhoto> for ProfilePhotoBuilder {
122    fn as_ref(&self) -> &ProfilePhoto {
123        &self.inner
124    }
125}