rust_tdlib/types/
bot_commands.rs1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct BotCommands {
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(default)]
16 bot_user_id: i64,
17 #[serde(default)]
20 commands: Vec<BotCommand>,
21}
22
23impl RObject for BotCommands {
24 #[doc(hidden)]
25 fn extra(&self) -> Option<&str> {
26 self.extra.as_deref()
27 }
28 #[doc(hidden)]
29 fn client_id(&self) -> Option<i32> {
30 self.client_id
31 }
32}
33
34impl BotCommands {
35 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
36 Ok(serde_json::from_str(json.as_ref())?)
37 }
38 pub fn builder() -> BotCommandsBuilder {
39 let mut inner = BotCommands::default();
40 inner.extra = Some(Uuid::new_v4().to_string());
41
42 BotCommandsBuilder { inner }
43 }
44
45 pub fn bot_user_id(&self) -> i64 {
46 self.bot_user_id
47 }
48
49 pub fn commands(&self) -> &Vec<BotCommand> {
50 &self.commands
51 }
52}
53
54#[doc(hidden)]
55pub struct BotCommandsBuilder {
56 inner: BotCommands,
57}
58
59#[deprecated]
60pub type RTDBotCommandsBuilder = BotCommandsBuilder;
61
62impl BotCommandsBuilder {
63 pub fn build(&self) -> BotCommands {
64 self.inner.clone()
65 }
66
67 pub fn bot_user_id(&mut self, bot_user_id: i64) -> &mut Self {
68 self.inner.bot_user_id = bot_user_id;
69 self
70 }
71
72 pub fn commands(&mut self, commands: Vec<BotCommand>) -> &mut Self {
73 self.inner.commands = commands;
74 self
75 }
76}
77
78impl AsRef<BotCommands> for BotCommands {
79 fn as_ref(&self) -> &BotCommands {
80 self
81 }
82}
83
84impl AsRef<BotCommands> for BotCommandsBuilder {
85 fn as_ref(&self) -> &BotCommands {
86 &self.inner
87 }
88}