rust_tdlib/types/
set_background.rs

1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5/// Changes the background selected by the user; adds background to the list of installed backgrounds
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct SetBackground {
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    /// The input background to use; pass null to create a new filled backgrounds or to remove the current background
14
15    #[serde(skip_serializing_if = "InputBackground::_is_default")]
16    background: InputBackground,
17    /// Background type; pass null to use the default type of the remote background or to remove the current background
18
19    #[serde(rename(serialize = "type", deserialize = "type"))]
20    #[serde(skip_serializing_if = "BackgroundType::_is_default")]
21    type_: BackgroundType,
22    /// True, if the background is chosen for dark theme
23
24    #[serde(default)]
25    for_dark_theme: bool,
26
27    #[serde(rename(serialize = "@type"))]
28    td_type: String,
29}
30
31impl RObject for SetBackground {
32    #[doc(hidden)]
33    fn extra(&self) -> Option<&str> {
34        self.extra.as_deref()
35    }
36    #[doc(hidden)]
37    fn client_id(&self) -> Option<i32> {
38        self.client_id
39    }
40}
41
42impl RFunction for SetBackground {}
43
44impl SetBackground {
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() -> SetBackgroundBuilder {
49        let mut inner = SetBackground::default();
50        inner.extra = Some(Uuid::new_v4().to_string());
51
52        inner.td_type = "setBackground".to_string();
53
54        SetBackgroundBuilder { inner }
55    }
56
57    pub fn background(&self) -> &InputBackground {
58        &self.background
59    }
60
61    pub fn type_(&self) -> &BackgroundType {
62        &self.type_
63    }
64
65    pub fn for_dark_theme(&self) -> bool {
66        self.for_dark_theme
67    }
68}
69
70#[doc(hidden)]
71pub struct SetBackgroundBuilder {
72    inner: SetBackground,
73}
74
75#[deprecated]
76pub type RTDSetBackgroundBuilder = SetBackgroundBuilder;
77
78impl SetBackgroundBuilder {
79    pub fn build(&self) -> SetBackground {
80        self.inner.clone()
81    }
82
83    pub fn background<T: AsRef<InputBackground>>(&mut self, background: T) -> &mut Self {
84        self.inner.background = background.as_ref().clone();
85        self
86    }
87
88    pub fn type_<T: AsRef<BackgroundType>>(&mut self, type_: T) -> &mut Self {
89        self.inner.type_ = type_.as_ref().clone();
90        self
91    }
92
93    pub fn for_dark_theme(&mut self, for_dark_theme: bool) -> &mut Self {
94        self.inner.for_dark_theme = for_dark_theme;
95        self
96    }
97}
98
99impl AsRef<SetBackground> for SetBackground {
100    fn as_ref(&self) -> &SetBackground {
101        self
102    }
103}
104
105impl AsRef<SetBackground> for SetBackgroundBuilder {
106    fn as_ref(&self) -> &SetBackground {
107        &self.inner
108    }
109}