rust_tdlib/types/
set_commands.rs1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct SetCommands {
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(skip_serializing_if = "BotCommandScope::_is_default")]
16 scope: BotCommandScope,
17 #[serde(default)]
20 language_code: String,
21 #[serde(default)]
24 commands: Vec<BotCommand>,
25
26 #[serde(rename(serialize = "@type"))]
27 td_type: String,
28}
29
30impl RObject for SetCommands {
31 #[doc(hidden)]
32 fn extra(&self) -> Option<&str> {
33 self.extra.as_deref()
34 }
35 #[doc(hidden)]
36 fn client_id(&self) -> Option<i32> {
37 self.client_id
38 }
39}
40
41impl RFunction for SetCommands {}
42
43impl SetCommands {
44 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
45 Ok(serde_json::from_str(json.as_ref())?)
46 }
47 pub fn builder() -> SetCommandsBuilder {
48 let mut inner = SetCommands::default();
49 inner.extra = Some(Uuid::new_v4().to_string());
50
51 inner.td_type = "setCommands".to_string();
52
53 SetCommandsBuilder { inner }
54 }
55
56 pub fn scope(&self) -> &BotCommandScope {
57 &self.scope
58 }
59
60 pub fn language_code(&self) -> &String {
61 &self.language_code
62 }
63
64 pub fn commands(&self) -> &Vec<BotCommand> {
65 &self.commands
66 }
67}
68
69#[doc(hidden)]
70pub struct SetCommandsBuilder {
71 inner: SetCommands,
72}
73
74#[deprecated]
75pub type RTDSetCommandsBuilder = SetCommandsBuilder;
76
77impl SetCommandsBuilder {
78 pub fn build(&self) -> SetCommands {
79 self.inner.clone()
80 }
81
82 pub fn scope<T: AsRef<BotCommandScope>>(&mut self, scope: T) -> &mut Self {
83 self.inner.scope = scope.as_ref().clone();
84 self
85 }
86
87 pub fn language_code<T: AsRef<str>>(&mut self, language_code: T) -> &mut Self {
88 self.inner.language_code = language_code.as_ref().to_string();
89 self
90 }
91
92 pub fn commands(&mut self, commands: Vec<BotCommand>) -> &mut Self {
93 self.inner.commands = commands;
94 self
95 }
96}
97
98impl AsRef<SetCommands> for SetCommands {
99 fn as_ref(&self) -> &SetCommands {
100 self
101 }
102}
103
104impl AsRef<SetCommands> for SetCommandsBuilder {
105 fn as_ref(&self) -> &SetCommands {
106 &self.inner
107 }
108}