rust_tdlib/types/
add_contact.rs1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct AddContact {
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 contact: Contact,
15 #[serde(default)]
18 share_phone_number: bool,
19
20 #[serde(rename(serialize = "@type"))]
21 td_type: String,
22}
23
24impl RObject for AddContact {
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 AddContact {}
36
37impl AddContact {
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() -> AddContactBuilder {
42 let mut inner = AddContact::default();
43 inner.extra = Some(Uuid::new_v4().to_string());
44
45 inner.td_type = "addContact".to_string();
46
47 AddContactBuilder { inner }
48 }
49
50 pub fn contact(&self) -> &Contact {
51 &self.contact
52 }
53
54 pub fn share_phone_number(&self) -> bool {
55 self.share_phone_number
56 }
57}
58
59#[doc(hidden)]
60pub struct AddContactBuilder {
61 inner: AddContact,
62}
63
64#[deprecated]
65pub type RTDAddContactBuilder = AddContactBuilder;
66
67impl AddContactBuilder {
68 pub fn build(&self) -> AddContact {
69 self.inner.clone()
70 }
71
72 pub fn contact<T: AsRef<Contact>>(&mut self, contact: T) -> &mut Self {
73 self.inner.contact = contact.as_ref().clone();
74 self
75 }
76
77 pub fn share_phone_number(&mut self, share_phone_number: bool) -> &mut Self {
78 self.inner.share_phone_number = share_phone_number;
79 self
80 }
81}
82
83impl AsRef<AddContact> for AddContact {
84 fn as_ref(&self) -> &AddContact {
85 self
86 }
87}
88
89impl AsRef<AddContact> for AddContactBuilder {
90 fn as_ref(&self) -> &AddContact {
91 &self.inner
92 }
93}