rust_tdlib/types/
get_option.rs

1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5/// Returns the value of an option by its name. (Check the list of available options on https://core.telegram.org/tdlib/options.) Can be called before authorization
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct GetOption {
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 name of the option
14
15    #[serde(default)]
16    name: String,
17
18    #[serde(rename(serialize = "@type"))]
19    td_type: String,
20}
21
22impl RObject for GetOption {
23    #[doc(hidden)]
24    fn extra(&self) -> Option<&str> {
25        self.extra.as_deref()
26    }
27    #[doc(hidden)]
28    fn client_id(&self) -> Option<i32> {
29        self.client_id
30    }
31}
32
33impl TDOptionValue for GetOption {}
34
35impl RFunction for GetOption {}
36
37impl GetOption {
38    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
39        Ok(serde_json::from_str(json.as_ref())?)
40    }
41    pub fn builder() -> GetOptionBuilder {
42        let mut inner = GetOption::default();
43        inner.extra = Some(Uuid::new_v4().to_string());
44
45        inner.td_type = "getOption".to_string();
46
47        GetOptionBuilder { inner }
48    }
49
50    pub fn name(&self) -> &String {
51        &self.name
52    }
53}
54
55#[doc(hidden)]
56pub struct GetOptionBuilder {
57    inner: GetOption,
58}
59
60#[deprecated]
61pub type RTDGetOptionBuilder = GetOptionBuilder;
62
63impl GetOptionBuilder {
64    pub fn build(&self) -> GetOption {
65        self.inner.clone()
66    }
67
68    pub fn name<T: AsRef<str>>(&mut self, name: T) -> &mut Self {
69        self.inner.name = name.as_ref().to_string();
70        self
71    }
72}
73
74impl AsRef<GetOption> for GetOption {
75    fn as_ref(&self) -> &GetOption {
76        self
77    }
78}
79
80impl AsRef<GetOption> for GetOptionBuilder {
81    fn as_ref(&self) -> &GetOption {
82        &self.inner
83    }
84}