zulip_api/message/
topic_link.rs1use serde::{Deserialize, Serialize};
2
3use crate::{field_access, impl_default, impl_display};
4
5#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
7pub struct TopicLink {
8 text: String,
9 url: String,
10}
11
12impl TopicLink {
13 pub const fn new() -> Self {
15 Self {
16 text: String::new(),
17 url: String::new(),
18 }
19 }
20}
21
22field_access! {
23 TopicLink {
24 text: cow { str },
25 url: cow { str },
26 }
27}
28
29impl_default!(TopicLink);
30impl_display!(TopicLink);
31
32#[cfg(test)]
33mod tests {
34 use super::*;
35
36 #[test]
37 fn test_topic_link() {
38 let text = "topic link text";
39 let url = "http://topic.link.url";
40 let topic_link = TopicLink::new().with_text(text).with_url(url);
41 let topic_link_json = topic_link.to_string();
42
43 assert_eq!(topic_link.text(), text);
44 assert_eq!(topic_link.url(), url);
45
46 assert_eq!(serde_json::to_string(&topic_link).unwrap(), topic_link_json);
47 assert_eq!(
48 serde_json::from_str::<TopicLink>(&topic_link_json).unwrap(),
49 topic_link
50 );
51 }
52}