rust_tdlib/types/
call_protocol.rs1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct CallProtocol {
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 #[serde(default)]
16 udp_p2p: bool,
17 #[serde(default)]
20 udp_reflector: bool,
21 #[serde(default)]
24 min_layer: i32,
25 #[serde(default)]
28 max_layer: i32,
29 #[serde(default)]
32 library_versions: Vec<String>,
33}
34
35impl RObject for CallProtocol {
36 #[doc(hidden)]
37 fn extra(&self) -> Option<&str> {
38 self.extra.as_deref()
39 }
40 #[doc(hidden)]
41 fn client_id(&self) -> Option<i32> {
42 self.client_id
43 }
44}
45
46impl CallProtocol {
47 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
48 Ok(serde_json::from_str(json.as_ref())?)
49 }
50 pub fn builder() -> CallProtocolBuilder {
51 let mut inner = CallProtocol::default();
52 inner.extra = Some(Uuid::new_v4().to_string());
53
54 CallProtocolBuilder { inner }
55 }
56
57 pub fn udp_p2p(&self) -> bool {
58 self.udp_p2p
59 }
60
61 pub fn udp_reflector(&self) -> bool {
62 self.udp_reflector
63 }
64
65 pub fn min_layer(&self) -> i32 {
66 self.min_layer
67 }
68
69 pub fn max_layer(&self) -> i32 {
70 self.max_layer
71 }
72
73 pub fn library_versions(&self) -> &Vec<String> {
74 &self.library_versions
75 }
76}
77
78#[doc(hidden)]
79pub struct CallProtocolBuilder {
80 inner: CallProtocol,
81}
82
83#[deprecated]
84pub type RTDCallProtocolBuilder = CallProtocolBuilder;
85
86impl CallProtocolBuilder {
87 pub fn build(&self) -> CallProtocol {
88 self.inner.clone()
89 }
90
91 pub fn udp_p2p(&mut self, udp_p2p: bool) -> &mut Self {
92 self.inner.udp_p2p = udp_p2p;
93 self
94 }
95
96 pub fn udp_reflector(&mut self, udp_reflector: bool) -> &mut Self {
97 self.inner.udp_reflector = udp_reflector;
98 self
99 }
100
101 pub fn min_layer(&mut self, min_layer: i32) -> &mut Self {
102 self.inner.min_layer = min_layer;
103 self
104 }
105
106 pub fn max_layer(&mut self, max_layer: i32) -> &mut Self {
107 self.inner.max_layer = max_layer;
108 self
109 }
110
111 pub fn library_versions(&mut self, library_versions: Vec<String>) -> &mut Self {
112 self.inner.library_versions = library_versions;
113 self
114 }
115}
116
117impl AsRef<CallProtocol> for CallProtocol {
118 fn as_ref(&self) -> &CallProtocol {
119 self
120 }
121}
122
123impl AsRef<CallProtocol> for CallProtocolBuilder {
124 fn as_ref(&self) -> &CallProtocol {
125 &self.inner
126 }
127}