rust_tdlib/types/
phone_number_info.rs

1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5/// Contains information about a phone number
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct PhoneNumberInfo {
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 country to which the phone number belongs; may be null
14    country: Option<CountryInfo>,
15    /// The part of the phone number denoting country calling code or its part
16
17    #[serde(default)]
18    country_calling_code: String,
19    /// The phone number without country calling code formatted accordingly to local rules. Expected digits are returned as '-', but even more digits might be entered by the user
20
21    #[serde(default)]
22    formatted_phone_number: String,
23}
24
25impl RObject for PhoneNumberInfo {
26    #[doc(hidden)]
27    fn extra(&self) -> Option<&str> {
28        self.extra.as_deref()
29    }
30    #[doc(hidden)]
31    fn client_id(&self) -> Option<i32> {
32        self.client_id
33    }
34}
35
36impl PhoneNumberInfo {
37    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
38        Ok(serde_json::from_str(json.as_ref())?)
39    }
40    pub fn builder() -> PhoneNumberInfoBuilder {
41        let mut inner = PhoneNumberInfo::default();
42        inner.extra = Some(Uuid::new_v4().to_string());
43
44        PhoneNumberInfoBuilder { inner }
45    }
46
47    pub fn country(&self) -> &Option<CountryInfo> {
48        &self.country
49    }
50
51    pub fn country_calling_code(&self) -> &String {
52        &self.country_calling_code
53    }
54
55    pub fn formatted_phone_number(&self) -> &String {
56        &self.formatted_phone_number
57    }
58}
59
60#[doc(hidden)]
61pub struct PhoneNumberInfoBuilder {
62    inner: PhoneNumberInfo,
63}
64
65#[deprecated]
66pub type RTDPhoneNumberInfoBuilder = PhoneNumberInfoBuilder;
67
68impl PhoneNumberInfoBuilder {
69    pub fn build(&self) -> PhoneNumberInfo {
70        self.inner.clone()
71    }
72
73    pub fn country<T: AsRef<CountryInfo>>(&mut self, country: T) -> &mut Self {
74        self.inner.country = Some(country.as_ref().clone());
75        self
76    }
77
78    pub fn country_calling_code<T: AsRef<str>>(&mut self, country_calling_code: T) -> &mut Self {
79        self.inner.country_calling_code = country_calling_code.as_ref().to_string();
80        self
81    }
82
83    pub fn formatted_phone_number<T: AsRef<str>>(
84        &mut self,
85        formatted_phone_number: T,
86    ) -> &mut Self {
87        self.inner.formatted_phone_number = formatted_phone_number.as_ref().to_string();
88        self
89    }
90}
91
92impl AsRef<PhoneNumberInfo> for PhoneNumberInfo {
93    fn as_ref(&self) -> &PhoneNumberInfo {
94        self
95    }
96}
97
98impl AsRef<PhoneNumberInfo> for PhoneNumberInfoBuilder {
99    fn as_ref(&self) -> &PhoneNumberInfo {
100        &self.inner
101    }
102}