rust_tdlib/types/
destroy.rs

1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5/// Closes the TDLib instance, destroying all local data without a proper logout. The current user session will remain in the list of all active sessions. All local data will be destroyed. After the destruction completes updateAuthorizationState with authorizationStateClosed will be sent. Can be called before authorization
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct Destroy {
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
14    #[serde(rename(serialize = "@type"))]
15    td_type: String,
16}
17
18impl RObject for Destroy {
19    #[doc(hidden)]
20    fn extra(&self) -> Option<&str> {
21        self.extra.as_deref()
22    }
23    #[doc(hidden)]
24    fn client_id(&self) -> Option<i32> {
25        self.client_id
26    }
27}
28
29impl RFunction for Destroy {}
30
31impl Destroy {
32    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
33        Ok(serde_json::from_str(json.as_ref())?)
34    }
35    pub fn builder() -> DestroyBuilder {
36        let mut inner = Destroy::default();
37        inner.extra = Some(Uuid::new_v4().to_string());
38
39        inner.td_type = "destroy".to_string();
40
41        DestroyBuilder { inner }
42    }
43}
44
45#[doc(hidden)]
46pub struct DestroyBuilder {
47    inner: Destroy,
48}
49
50#[deprecated]
51pub type RTDDestroyBuilder = DestroyBuilder;
52
53impl DestroyBuilder {
54    pub fn build(&self) -> Destroy {
55        self.inner.clone()
56    }
57}
58
59impl AsRef<Destroy> for Destroy {
60    fn as_ref(&self) -> &Destroy {
61        self
62    }
63}
64
65impl AsRef<Destroy> for DestroyBuilder {
66    fn as_ref(&self) -> &Destroy {
67        &self.inner
68    }
69}