rust_tdlib/types/
set_network_type.rs

1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5/// Sets the current network type. Can be called before authorization. Calling this method forces all network connections to reopen, mitigating the delay in switching between different networks, so it must be called whenever the network is changed, even if the network type remains the same. Network type is used to check whether the library can use the network at all and also for collecting detailed network data usage statistics
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct SetNetworkType {
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    /// The new network type; pass null to set network type to networkTypeOther
14
15    #[serde(rename(serialize = "type", deserialize = "type"))]
16    #[serde(skip_serializing_if = "NetworkType::_is_default")]
17    type_: NetworkType,
18
19    #[serde(rename(serialize = "@type"))]
20    td_type: String,
21}
22
23impl RObject for SetNetworkType {
24    #[doc(hidden)]
25    fn extra(&self) -> Option<&str> {
26        self.extra.as_deref()
27    }
28    #[doc(hidden)]
29    fn client_id(&self) -> Option<i32> {
30        self.client_id
31    }
32}
33
34impl RFunction for SetNetworkType {}
35
36impl SetNetworkType {
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() -> SetNetworkTypeBuilder {
41        let mut inner = SetNetworkType::default();
42        inner.extra = Some(Uuid::new_v4().to_string());
43
44        inner.td_type = "setNetworkType".to_string();
45
46        SetNetworkTypeBuilder { inner }
47    }
48
49    pub fn type_(&self) -> &NetworkType {
50        &self.type_
51    }
52}
53
54#[doc(hidden)]
55pub struct SetNetworkTypeBuilder {
56    inner: SetNetworkType,
57}
58
59#[deprecated]
60pub type RTDSetNetworkTypeBuilder = SetNetworkTypeBuilder;
61
62impl SetNetworkTypeBuilder {
63    pub fn build(&self) -> SetNetworkType {
64        self.inner.clone()
65    }
66
67    pub fn type_<T: AsRef<NetworkType>>(&mut self, type_: T) -> &mut Self {
68        self.inner.type_ = type_.as_ref().clone();
69        self
70    }
71}
72
73impl AsRef<SetNetworkType> for SetNetworkType {
74    fn as_ref(&self) -> &SetNetworkType {
75        self
76    }
77}
78
79impl AsRef<SetNetworkType> for SetNetworkTypeBuilder {
80    fn as_ref(&self) -> &SetNetworkType {
81        &self.inner
82    }
83}