zulip_api/message/
response.rs1mod base;
4mod error_code;
5mod result;
6
7pub use base::BaseResponse;
8pub use error_code::ErrorCode;
9pub use result::ApiResult;
10
11pub trait Response {
13 fn msg(&self) -> &str;
15
16 fn set_msg<'a, C: Into<std::borrow::Cow<'a, str>>>(&mut self, msg: C);
18
19 fn with_msg<'a, C: Into<std::borrow::Cow<'a, str>>>(self, msg: C) -> Self;
21
22 fn result(&self) -> ApiResult;
24
25 fn set_result(&mut self, result: ApiResult);
27
28 fn with_result(self, result: ApiResult) -> Self;
30
31 fn code(&self) -> Option<ErrorCode>;
33
34 fn set_code(&mut self, code: ErrorCode);
36
37 fn unset_code(&mut self) -> Option<ErrorCode>;
39
40 fn with_code(self, code: ErrorCode) -> Self;
42
43 fn ignored_parameters_unsupported(&self) -> Option<&[String]>;
51
52 fn set_ignored_parameters_unsupported<'a, C: Into<std::borrow::Cow<'a, [String]>>>(
60 &mut self,
61 val: C,
62 );
63
64 fn unset_ignored_parameters_unsupported(&mut self) -> Option<Vec<String>>;
72
73 fn with_ignored_parameters_unsupported<'a, C: Into<std::borrow::Cow<'a, [String]>>>(
81 self,
82 val: C,
83 ) -> Self;
84}
85
86#[macro_export]
88macro_rules! impl_response {
89 ($ty:ident) => {
90 impl $crate::response::Response for $ty {
91 fn msg(&self) -> &str {
92 &self.msg
93 }
94
95 fn set_msg<'a, C: Into<std::borrow::Cow<'a, str>>>(&mut self, msg: C) {
96 self.msg = C::into(msg).into();
97 }
98
99 fn with_msg<'a, C: Into<std::borrow::Cow<'a, str>>>(self, msg: C) -> Self {
100 Self {
101 msg: C::into(msg).into(),
102 ..self
103 }
104 }
105
106 fn result(&self) -> $crate::response::ApiResult {
107 self.result
108 }
109
110 fn set_result(&mut self, result: $crate::response::ApiResult) {
111 self.result = result;
112 }
113
114 fn with_result(self, result: $crate::response::ApiResult) -> Self {
115 Self { result, ..self }
116 }
117
118 fn code(&self) -> Option<$crate::response::ErrorCode> {
119 self.code
120 }
121
122 fn set_code(&mut self, code: $crate::response::ErrorCode) {
123 self.code = Some(code);
124 }
125
126 fn unset_code(&mut self) -> Option<$crate::response::ErrorCode> {
127 self.code.take()
128 }
129
130 fn with_code(self, code: $crate::response::ErrorCode) -> Self {
131 Self {
132 code: Some(code),
133 ..self
134 }
135 }
136
137 fn ignored_parameters_unsupported(&self) -> Option<&[String]> {
138 self.ignored_parameters_unsupported.as_deref()
139 }
140
141 fn set_ignored_parameters_unsupported<'a, C: Into<std::borrow::Cow<'a, [String]>>>(
142 &mut self,
143 val: C,
144 ) {
145 self.ignored_parameters_unsupported = Some(C::into(val).into());
146 }
147
148 fn unset_ignored_parameters_unsupported(&mut self) -> Option<Vec<String>> {
149 self.ignored_parameters_unsupported.take()
150 }
151
152 fn with_ignored_parameters_unsupported<'a, C: Into<std::borrow::Cow<'a, [String]>>>(
153 self,
154 val: C,
155 ) -> Self {
156 Self {
157 ignored_parameters_unsupported: Some(C::into(val).into()),
158 ..self
159 }
160 }
161 }
162 };
163
164 ($ty:ident, $field:ident) => {
165 impl $crate::response::Response for $ty {
166 fn msg(&self) -> &str {
167 &self.$field.msg()
168 }
169
170 fn set_msg<'a, C: Into<std::borrow::Cow<'a, str>>>(&mut self, msg: C) {
171 self.$field.set_msg(msg);
172 }
173
174 fn with_msg<'a, C: Into<std::borrow::Cow<'a, str>>>(self, msg: C) -> Self {
175 Self {
176 $field: self.$field.with_msg(msg),
177 ..self
178 }
179 }
180
181 fn result(&self) -> $crate::response::ApiResult {
182 self.$field.result()
183 }
184
185 fn set_result(&mut self, result: $crate::response::ApiResult) {
186 self.$field.set_result(result);
187 }
188
189 fn with_result(self, result: $crate::response::ApiResult) -> Self {
190 Self {
191 $field: self.$field.with_result(result),
192 ..self
193 }
194 }
195
196 fn code(&self) -> Option<$crate::response::ErrorCode> {
197 self.$field.code()
198 }
199
200 fn set_code(&mut self, code: $crate::response::ErrorCode) {
201 self.$field.set_code(code);
202 }
203
204 fn unset_code(&mut self) -> Option<$crate::response::ErrorCode> {
205 self.$field.unset_code()
206 }
207
208 fn with_code(self, code: $crate::response::ErrorCode) -> Self {
209 Self {
210 $field: self.$field.with_code(code),
211 ..self
212 }
213 }
214
215 fn ignored_parameters_unsupported(&self) -> Option<&[String]> {
216 self.$field.ignored_parameters_unsupported()
217 }
218
219 fn set_ignored_parameters_unsupported<'a, C: Into<std::borrow::Cow<'a, [String]>>>(
220 &mut self,
221 val: C,
222 ) {
223 self.$field.set_ignored_parameters_unsupported(val);
224 }
225
226 fn unset_ignored_parameters_unsupported(&mut self) -> Option<Vec<String>> {
227 self.$field.unset_ignored_parameters_unsupported()
228 }
229
230 fn with_ignored_parameters_unsupported<'a, C: Into<std::borrow::Cow<'a, [String]>>>(
231 self,
232 val: C,
233 ) -> Self {
234 Self {
235 $field: self.$field.with_ignored_parameters_unsupported(val),
236 ..self
237 }
238 }
239 }
240 };
241}