rust_tdlib/types/
chat_photo.rs1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct ChatPhoto {
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 #[serde(default)]
24 added_date: i32,
25 minithumbnail: Option<Minithumbnail>,
27 #[serde(default)]
30 sizes: Vec<PhotoSize>,
31 animation: Option<AnimatedChatPhoto>,
33}
34
35impl RObject for ChatPhoto {
36 #[doc(hidden)]
37 fn extra(&self) -> Option<&str> {
38 self.extra.as_deref()
39 }
40 #[doc(hidden)]
41 fn client_id(&self) -> Option<i32> {
42 self.client_id
43 }
44}
45
46impl ChatPhoto {
47 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
48 Ok(serde_json::from_str(json.as_ref())?)
49 }
50 pub fn builder() -> ChatPhotoBuilder {
51 let mut inner = ChatPhoto::default();
52 inner.extra = Some(Uuid::new_v4().to_string());
53
54 ChatPhotoBuilder { inner }
55 }
56
57 pub fn id(&self) -> i64 {
58 self.id
59 }
60
61 pub fn added_date(&self) -> i32 {
62 self.added_date
63 }
64
65 pub fn minithumbnail(&self) -> &Option<Minithumbnail> {
66 &self.minithumbnail
67 }
68
69 pub fn sizes(&self) -> &Vec<PhotoSize> {
70 &self.sizes
71 }
72
73 pub fn animation(&self) -> &Option<AnimatedChatPhoto> {
74 &self.animation
75 }
76}
77
78#[doc(hidden)]
79pub struct ChatPhotoBuilder {
80 inner: ChatPhoto,
81}
82
83#[deprecated]
84pub type RTDChatPhotoBuilder = ChatPhotoBuilder;
85
86impl ChatPhotoBuilder {
87 pub fn build(&self) -> ChatPhoto {
88 self.inner.clone()
89 }
90
91 pub fn id(&mut self, id: i64) -> &mut Self {
92 self.inner.id = id;
93 self
94 }
95
96 pub fn added_date(&mut self, added_date: i32) -> &mut Self {
97 self.inner.added_date = added_date;
98 self
99 }
100
101 pub fn minithumbnail<T: AsRef<Minithumbnail>>(&mut self, minithumbnail: T) -> &mut Self {
102 self.inner.minithumbnail = Some(minithumbnail.as_ref().clone());
103 self
104 }
105
106 pub fn sizes(&mut self, sizes: Vec<PhotoSize>) -> &mut Self {
107 self.inner.sizes = sizes;
108 self
109 }
110
111 pub fn animation<T: AsRef<AnimatedChatPhoto>>(&mut self, animation: T) -> &mut Self {
112 self.inner.animation = Some(animation.as_ref().clone());
113 self
114 }
115}
116
117impl AsRef<ChatPhoto> for ChatPhoto {
118 fn as_ref(&self) -> &ChatPhoto {
119 self
120 }
121}
122
123impl AsRef<ChatPhoto> for ChatPhotoBuilder {
124 fn as_ref(&self) -> &ChatPhoto {
125 &self.inner
126 }
127}