rust_tdlib/types/
recover_password.rs

1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5/// Recovers the 2-step verification password using a recovery code sent to an email address that was previously set up
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct RecoverPassword {
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    /// Recovery code to check
14
15    #[serde(default)]
16    recovery_code: String,
17    /// New password of the user; may be empty to remove the password
18
19    #[serde(default)]
20    new_password: String,
21    /// New password hint; may be empty
22
23    #[serde(default)]
24    new_hint: String,
25
26    #[serde(rename(serialize = "@type"))]
27    td_type: String,
28}
29
30impl RObject for RecoverPassword {
31    #[doc(hidden)]
32    fn extra(&self) -> Option<&str> {
33        self.extra.as_deref()
34    }
35    #[doc(hidden)]
36    fn client_id(&self) -> Option<i32> {
37        self.client_id
38    }
39}
40
41impl RFunction for RecoverPassword {}
42
43impl RecoverPassword {
44    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
45        Ok(serde_json::from_str(json.as_ref())?)
46    }
47    pub fn builder() -> RecoverPasswordBuilder {
48        let mut inner = RecoverPassword::default();
49        inner.extra = Some(Uuid::new_v4().to_string());
50
51        inner.td_type = "recoverPassword".to_string();
52
53        RecoverPasswordBuilder { inner }
54    }
55
56    pub fn recovery_code(&self) -> &String {
57        &self.recovery_code
58    }
59
60    pub fn new_password(&self) -> &String {
61        &self.new_password
62    }
63
64    pub fn new_hint(&self) -> &String {
65        &self.new_hint
66    }
67}
68
69#[doc(hidden)]
70pub struct RecoverPasswordBuilder {
71    inner: RecoverPassword,
72}
73
74#[deprecated]
75pub type RTDRecoverPasswordBuilder = RecoverPasswordBuilder;
76
77impl RecoverPasswordBuilder {
78    pub fn build(&self) -> RecoverPassword {
79        self.inner.clone()
80    }
81
82    pub fn recovery_code<T: AsRef<str>>(&mut self, recovery_code: T) -> &mut Self {
83        self.inner.recovery_code = recovery_code.as_ref().to_string();
84        self
85    }
86
87    pub fn new_password<T: AsRef<str>>(&mut self, new_password: T) -> &mut Self {
88        self.inner.new_password = new_password.as_ref().to_string();
89        self
90    }
91
92    pub fn new_hint<T: AsRef<str>>(&mut self, new_hint: T) -> &mut Self {
93        self.inner.new_hint = new_hint.as_ref().to_string();
94        self
95    }
96}
97
98impl AsRef<RecoverPassword> for RecoverPassword {
99    fn as_ref(&self) -> &RecoverPassword {
100        self
101    }
102}
103
104impl AsRef<RecoverPassword> for RecoverPasswordBuilder {
105    fn as_ref(&self) -> &RecoverPassword {
106        &self.inner
107    }
108}