rust_tdlib/types/
set_custom_language_pack.rs

1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5/// Adds or changes a custom local language pack to the current localization target
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct SetCustomLanguagePack {
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    /// Information about the language pack. Language pack ID must start with 'X', consist only of English letters, digits and hyphens, and must not exceed 64 characters. Can be called before authorization
14    info: LanguagePackInfo,
15    /// Strings of the new language pack
16
17    #[serde(default)]
18    strings: Vec<LanguagePackString>,
19
20    #[serde(rename(serialize = "@type"))]
21    td_type: String,
22}
23
24impl RObject for SetCustomLanguagePack {
25    #[doc(hidden)]
26    fn extra(&self) -> Option<&str> {
27        self.extra.as_deref()
28    }
29    #[doc(hidden)]
30    fn client_id(&self) -> Option<i32> {
31        self.client_id
32    }
33}
34
35impl RFunction for SetCustomLanguagePack {}
36
37impl SetCustomLanguagePack {
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() -> SetCustomLanguagePackBuilder {
42        let mut inner = SetCustomLanguagePack::default();
43        inner.extra = Some(Uuid::new_v4().to_string());
44
45        inner.td_type = "setCustomLanguagePack".to_string();
46
47        SetCustomLanguagePackBuilder { inner }
48    }
49
50    pub fn info(&self) -> &LanguagePackInfo {
51        &self.info
52    }
53
54    pub fn strings(&self) -> &Vec<LanguagePackString> {
55        &self.strings
56    }
57}
58
59#[doc(hidden)]
60pub struct SetCustomLanguagePackBuilder {
61    inner: SetCustomLanguagePack,
62}
63
64#[deprecated]
65pub type RTDSetCustomLanguagePackBuilder = SetCustomLanguagePackBuilder;
66
67impl SetCustomLanguagePackBuilder {
68    pub fn build(&self) -> SetCustomLanguagePack {
69        self.inner.clone()
70    }
71
72    pub fn info<T: AsRef<LanguagePackInfo>>(&mut self, info: T) -> &mut Self {
73        self.inner.info = info.as_ref().clone();
74        self
75    }
76
77    pub fn strings(&mut self, strings: Vec<LanguagePackString>) -> &mut Self {
78        self.inner.strings = strings;
79        self
80    }
81}
82
83impl AsRef<SetCustomLanguagePack> for SetCustomLanguagePack {
84    fn as_ref(&self) -> &SetCustomLanguagePack {
85        self
86    }
87}
88
89impl AsRef<SetCustomLanguagePack> for SetCustomLanguagePackBuilder {
90    fn as_ref(&self) -> &SetCustomLanguagePack {
91        &self.inner
92    }
93}