zulip_api/message/get_message/
response.rs1use serde::{Deserialize, Serialize};
2
3use crate::response::BaseResponse;
4use crate::{field_access, impl_default, impl_display, impl_response, Message};
5
6#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
10pub struct Response {
11 #[serde(flatten)]
12 base: BaseResponse,
13 #[serde(skip_serializing_if = "Option::is_none")]
14 raw_content: Option<String>,
15 #[serde(skip_serializing_if = "Option::is_none")]
16 message: Option<Message>,
17}
18
19impl Response {
20 pub const fn new() -> Self {
22 Self {
23 base: BaseResponse::new(),
24 raw_content: None,
25 message: None,
26 }
27 }
28}
29
30field_access! {
31 Response {
32 raw_content: option_cow_deref { str, String },
40 }
41}
42
43field_access! {
44 Response {
45 message: option_cow_ref { Message },
47 }
48}
49
50impl_default!(Response);
51impl_display!(Response);
52impl_response!(Response, base);
53
54#[cfg(test)]
55mod tests {
56 use super::*;
57
58 #[test]
59 fn test_response() {
60 let raw_content = "test raw cnntent";
61 let message = Message::new();
62
63 let response = Response::new()
64 .with_raw_content(raw_content)
65 .with_message(&message);
66 let response_json = response.to_string();
67
68 assert_eq!(serde_json::to_string(&response).unwrap(), response_json);
69 assert_eq!(
70 serde_json::from_str::<Response>(&response_json).unwrap(),
71 response
72 );
73
74 assert_eq!(response.raw_content(), Some(raw_content));
75 assert_eq!(response.message(), Some(&message));
76 }
77}