rust_tdlib/types/
account_ttl.rs

1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5/// Contains information about the period of inactivity after which the current user's account will automatically be deleted
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct AccountTtl {
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    /// Number of days of inactivity before the account will be flagged for deletion; 30-366 days
14
15    #[serde(default)]
16    days: i32,
17}
18
19impl RObject for AccountTtl {
20    #[doc(hidden)]
21    fn extra(&self) -> Option<&str> {
22        self.extra.as_deref()
23    }
24    #[doc(hidden)]
25    fn client_id(&self) -> Option<i32> {
26        self.client_id
27    }
28}
29
30impl AccountTtl {
31    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
32        Ok(serde_json::from_str(json.as_ref())?)
33    }
34    pub fn builder() -> AccountTtlBuilder {
35        let mut inner = AccountTtl::default();
36        inner.extra = Some(Uuid::new_v4().to_string());
37
38        AccountTtlBuilder { inner }
39    }
40
41    pub fn days(&self) -> i32 {
42        self.days
43    }
44}
45
46#[doc(hidden)]
47pub struct AccountTtlBuilder {
48    inner: AccountTtl,
49}
50
51#[deprecated]
52pub type RTDAccountTtlBuilder = AccountTtlBuilder;
53
54impl AccountTtlBuilder {
55    pub fn build(&self) -> AccountTtl {
56        self.inner.clone()
57    }
58
59    pub fn days(&mut self, days: i32) -> &mut Self {
60        self.inner.days = days;
61        self
62    }
63}
64
65impl AsRef<AccountTtl> for AccountTtl {
66    fn as_ref(&self) -> &AccountTtl {
67        self
68    }
69}
70
71impl AsRef<AccountTtl> for AccountTtlBuilder {
72    fn as_ref(&self) -> &AccountTtl {
73        &self.inner
74    }
75}