rust_tdlib/types/
bot_command.rs1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct BotCommand {
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 command: String,
17 #[serde(default)]
20 description: String,
21}
22
23impl RObject for BotCommand {
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 BotCommand {
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() -> BotCommandBuilder {
39 let mut inner = BotCommand::default();
40 inner.extra = Some(Uuid::new_v4().to_string());
41
42 BotCommandBuilder { inner }
43 }
44
45 pub fn command(&self) -> &String {
46 &self.command
47 }
48
49 pub fn description(&self) -> &String {
50 &self.description
51 }
52}
53
54#[doc(hidden)]
55pub struct BotCommandBuilder {
56 inner: BotCommand,
57}
58
59#[deprecated]
60pub type RTDBotCommandBuilder = BotCommandBuilder;
61
62impl BotCommandBuilder {
63 pub fn build(&self) -> BotCommand {
64 self.inner.clone()
65 }
66
67 pub fn command<T: AsRef<str>>(&mut self, command: T) -> &mut Self {
68 self.inner.command = command.as_ref().to_string();
69 self
70 }
71
72 pub fn description<T: AsRef<str>>(&mut self, description: T) -> &mut Self {
73 self.inner.description = description.as_ref().to_string();
74 self
75 }
76}
77
78impl AsRef<BotCommand> for BotCommand {
79 fn as_ref(&self) -> &BotCommand {
80 self
81 }
82}
83
84impl AsRef<BotCommand> for BotCommandBuilder {
85 fn as_ref(&self) -> &BotCommand {
86 &self.inner
87 }
88}