1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
//! Zulip API response types.
mod base;
mod error_code;
mod result;
pub use base::BaseResponse;
pub use error_code::ErrorCode;
pub use result::ApiResult;
/// Represents the common functions for all response types.
pub trait Response {
/// Gets the [Response] `msg` field.
fn msg(&self) -> &str;
/// Sets the [Response] `msg` field.
fn set_msg<'a, C: Into<std::borrow::Cow<'a, str>>>(&mut self, msg: C);
/// Builder function that sets the [Response] `msg` field.
fn with_msg<'a, C: Into<std::borrow::Cow<'a, str>>>(self, msg: C) -> Self;
/// Gets the [Response] `result` field.
fn result(&self) -> ApiResult;
/// Sets the [Response] `result` field.
fn set_result(&mut self, result: ApiResult);
/// Builder function that sets the [Response] `result` field.
fn with_result(self, result: ApiResult) -> Self;
/// Gets the [Response] `code` field.
fn code(&self) -> Option<ErrorCode>;
/// Sets the [Response] `code` field.
fn set_code(&mut self, code: ErrorCode);
/// Unsets the [Response] `code` field.
fn unset_code(&mut self) -> Option<ErrorCode>;
/// Builder function that sets the [Response] `code` field.
fn with_code(self, code: ErrorCode) -> Self;
/// Gets the [Response] ignored unsupported parameters list.
///
/// An array of any parameters sent in the request that are not
/// supported by the endpoint.
///
/// See [error handling](https://zulip.com//api/rest-error-handling#ignored-parameters) documentation
/// for details on this and its change history.
fn ignored_parameters_unsupported(&self) -> Option<&[String]>;
/// Sets the [Response] ignored unsupported parameters list.
///
/// An array of any parameters sent in the request that are not
/// supported by the endpoint.
///
/// See [error handling](https://zulip.com//api/rest-error-handling#ignored-parameters) documentation
/// for details on this and its change history.
fn set_ignored_parameters_unsupported<'a, C: Into<std::borrow::Cow<'a, [String]>>>(
&mut self,
val: C,
);
/// Unsets the [Response] ignored unsupported parameters list.
///
/// An array of any parameters sent in the request that are not
/// supported by the endpoint.
///
/// See [error handling](https://zulip.com//api/rest-error-handling#ignored-parameters) documentation
/// for details on this and its change history.
fn unset_ignored_parameters_unsupported(&mut self) -> Option<Vec<String>>;
/// Builder function that sets the [Response] ignored unsupported parameters list.
///
/// An array of any parameters sent in the request that are not
/// supported by the endpoint.
///
/// See [error handling](https://zulip.com//api/rest-error-handling#ignored-parameters) documentation
/// for details on this and its change history.
fn with_ignored_parameters_unsupported<'a, C: Into<std::borrow::Cow<'a, [String]>>>(
self,
val: C,
) -> Self;
}
/// Implements the [Response] trait for a given type.
#[macro_export]
macro_rules! impl_response {
($ty:ident) => {
impl $crate::response::Response for $ty {
fn msg(&self) -> &str {
&self.msg
}
fn set_msg<'a, C: Into<std::borrow::Cow<'a, str>>>(&mut self, msg: C) {
self.msg = C::into(msg).into();
}
fn with_msg<'a, C: Into<std::borrow::Cow<'a, str>>>(self, msg: C) -> Self {
Self {
msg: C::into(msg).into(),
..self
}
}
fn result(&self) -> $crate::response::ApiResult {
self.result
}
fn set_result(&mut self, result: $crate::response::ApiResult) {
self.result = result;
}
fn with_result(self, result: $crate::response::ApiResult) -> Self {
Self { result, ..self }
}
fn code(&self) -> Option<$crate::response::ErrorCode> {
self.code
}
fn set_code(&mut self, code: $crate::response::ErrorCode) {
self.code = Some(code);
}
fn unset_code(&mut self) -> Option<$crate::response::ErrorCode> {
self.code.take()
}
fn with_code(self, code: $crate::response::ErrorCode) -> Self {
Self {
code: Some(code),
..self
}
}
fn ignored_parameters_unsupported(&self) -> Option<&[String]> {
self.ignored_parameters_unsupported.as_deref()
}
fn set_ignored_parameters_unsupported<'a, C: Into<std::borrow::Cow<'a, [String]>>>(
&mut self,
val: C,
) {
self.ignored_parameters_unsupported = Some(C::into(val).into());
}
fn unset_ignored_parameters_unsupported(&mut self) -> Option<Vec<String>> {
self.ignored_parameters_unsupported.take()
}
fn with_ignored_parameters_unsupported<'a, C: Into<std::borrow::Cow<'a, [String]>>>(
self,
val: C,
) -> Self {
Self {
ignored_parameters_unsupported: Some(C::into(val).into()),
..self
}
}
}
};
($ty:ident, $field:ident) => {
impl $crate::response::Response for $ty {
fn msg(&self) -> &str {
&self.$field.msg()
}
fn set_msg<'a, C: Into<std::borrow::Cow<'a, str>>>(&mut self, msg: C) {
self.$field.set_msg(msg);
}
fn with_msg<'a, C: Into<std::borrow::Cow<'a, str>>>(self, msg: C) -> Self {
Self {
$field: self.$field.with_msg(msg),
..self
}
}
fn result(&self) -> $crate::response::ApiResult {
self.$field.result()
}
fn set_result(&mut self, result: $crate::response::ApiResult) {
self.$field.set_result(result);
}
fn with_result(self, result: $crate::response::ApiResult) -> Self {
Self {
$field: self.$field.with_result(result),
..self
}
}
fn code(&self) -> Option<$crate::response::ErrorCode> {
self.$field.code()
}
fn set_code(&mut self, code: $crate::response::ErrorCode) {
self.$field.set_code(code);
}
fn unset_code(&mut self) -> Option<$crate::response::ErrorCode> {
self.$field.unset_code()
}
fn with_code(self, code: $crate::response::ErrorCode) -> Self {
Self {
$field: self.$field.with_code(code),
..self
}
}
fn ignored_parameters_unsupported(&self) -> Option<&[String]> {
self.$field.ignored_parameters_unsupported()
}
fn set_ignored_parameters_unsupported<'a, C: Into<std::borrow::Cow<'a, [String]>>>(
&mut self,
val: C,
) {
self.$field.set_ignored_parameters_unsupported(val);
}
fn unset_ignored_parameters_unsupported(&mut self) -> Option<Vec<String>> {
self.$field.unset_ignored_parameters_unsupported()
}
fn with_ignored_parameters_unsupported<'a, C: Into<std::borrow::Cow<'a, [String]>>>(
self,
val: C,
) -> Self {
Self {
$field: self.$field.with_ignored_parameters_unsupported(val),
..self
}
}
}
};
}