rust_tdlib/types/
profile_photo.rs1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5#[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 #[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 small: File,
23 big: File,
25 minithumbnail: Option<Minithumbnail>,
27 #[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}