rtdlib/types/
password_state.rs

1
2use crate::types::*;
3use crate::errors::*;
4use uuid::Uuid;
5
6
7
8
9/// Represents the current state of 2-step verification
10#[derive(Debug, Clone, Default, Serialize, Deserialize)]
11pub struct PasswordState {
12  #[doc(hidden)]
13  #[serde(rename(serialize = "@type", deserialize = "@type"))]
14  td_name: String,
15  #[doc(hidden)]
16  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
17  extra: Option<String>,
18  /// True, if a 2-step verification password is set
19  has_password: bool,
20  /// Hint for the password; may be empty
21  password_hint: String,
22  /// True, if a recovery email is set
23  has_recovery_email_address: bool,
24  /// True, if some Telegram Passport elements were saved
25  has_passport_data: bool,
26  /// Information about the recovery email address to which the confirmation email was sent; may be null
27  recovery_email_address_code_info: Option<EmailAddressAuthenticationCodeInfo>,
28  /// If not 0, point in time (Unix timestamp) after which the password can be reset immediately using resetPassword
29  pending_reset_date: i64,
30  
31}
32
33impl RObject for PasswordState {
34  #[doc(hidden)] fn td_name(&self) -> &'static str { "passwordState" }
35  #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
36  fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
37}
38
39
40
41impl PasswordState {
42  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
43  pub fn builder() -> RTDPasswordStateBuilder {
44    let mut inner = PasswordState::default();
45    inner.td_name = "passwordState".to_string();
46    inner.extra = Some(Uuid::new_v4().to_string());
47    RTDPasswordStateBuilder { inner }
48  }
49
50  pub fn has_password(&self) -> bool { self.has_password }
51
52  pub fn password_hint(&self) -> &String { &self.password_hint }
53
54  pub fn has_recovery_email_address(&self) -> bool { self.has_recovery_email_address }
55
56  pub fn has_passport_data(&self) -> bool { self.has_passport_data }
57
58  pub fn recovery_email_address_code_info(&self) -> &Option<EmailAddressAuthenticationCodeInfo> { &self.recovery_email_address_code_info }
59
60  pub fn pending_reset_date(&self) -> i64 { self.pending_reset_date }
61
62}
63
64#[doc(hidden)]
65pub struct RTDPasswordStateBuilder {
66  inner: PasswordState
67}
68
69impl RTDPasswordStateBuilder {
70  pub fn build(&self) -> PasswordState { self.inner.clone() }
71
72   
73  pub fn has_password(&mut self, has_password: bool) -> &mut Self {
74    self.inner.has_password = has_password;
75    self
76  }
77
78   
79  pub fn password_hint<T: AsRef<str>>(&mut self, password_hint: T) -> &mut Self {
80    self.inner.password_hint = password_hint.as_ref().to_string();
81    self
82  }
83
84   
85  pub fn has_recovery_email_address(&mut self, has_recovery_email_address: bool) -> &mut Self {
86    self.inner.has_recovery_email_address = has_recovery_email_address;
87    self
88  }
89
90   
91  pub fn has_passport_data(&mut self, has_passport_data: bool) -> &mut Self {
92    self.inner.has_passport_data = has_passport_data;
93    self
94  }
95
96   
97  pub fn recovery_email_address_code_info<T: AsRef<EmailAddressAuthenticationCodeInfo>>(&mut self, recovery_email_address_code_info: T) -> &mut Self {
98    self.inner.recovery_email_address_code_info = Some(recovery_email_address_code_info.as_ref().clone());
99    self
100  }
101
102   
103  pub fn pending_reset_date(&mut self, pending_reset_date: i64) -> &mut Self {
104    self.inner.pending_reset_date = pending_reset_date;
105    self
106  }
107
108}
109
110impl AsRef<PasswordState> for PasswordState {
111  fn as_ref(&self) -> &PasswordState { self }
112}
113
114impl AsRef<PasswordState> for RTDPasswordStateBuilder {
115  fn as_ref(&self) -> &PasswordState { &self.inner }
116}
117
118
119