zulip_api/message/
default_channel_group.rs1use serde::{Deserialize, Serialize};
2
3use crate::{field_access, impl_cow, impl_default, impl_display};
4
5#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
29pub struct DefaultChannelGroup {
30 #[serde(skip_serializing_if = "Option::is_none")]
31 name: Option<String>,
32 #[serde(skip_serializing_if = "Option::is_none")]
33 description: Option<String>,
34 #[serde(skip_serializing_if = "Option::is_none")]
35 id: Option<u64>,
36 #[serde(skip_serializing_if = "Option::is_none")]
37 streams: Option<Vec<u64>>,
38}
39
40impl DefaultChannelGroup {
41 pub const fn new() -> Self {
43 Self {
44 name: None,
45 description: None,
46 id: None,
47 streams: None,
48 }
49 }
50}
51
52field_access! {
53 DefaultChannelGroup {
54 name: option_cow_deref { str, String },
56 description: option_cow_deref { str, String },
58 streams: option_cow_deref { [u64], Vec<u64> },
62 }
63}
64
65field_access! {
66 DefaultChannelGroup {
67 id: option { u64 },
69 }
70}
71
72impl_cow!(DefaultChannelGroup);
73impl_default!(DefaultChannelGroup);
74impl_display!(DefaultChannelGroup);
75
76#[cfg(test)]
77mod tests {
78 use super::*;
79
80 #[test]
81 fn test_default_channel_group() {
82 let name = "test name";
83 let description = "test description";
84 let id = 1;
85 let streams = [1u64];
86
87 let group = DefaultChannelGroup::new()
88 .with_name(name)
89 .with_description(description)
90 .with_id(id)
91 .with_streams(streams.as_ref());
92 let group_json = group.to_string();
93
94 assert_eq!(serde_json::to_string(&group).unwrap(), group_json);
95 assert_eq!(
96 serde_json::from_str::<DefaultChannelGroup>(&group_json).unwrap(),
97 group
98 );
99
100 assert_eq!(group.name(), Some(name));
101 assert_eq!(group.description(), Some(description));
102 assert_eq!(group.id(), Some(id));
103 assert_eq!(group.streams(), Some(streams.as_ref()));
104 }
105}