use serde::{Deserialize, Serialize};
use crate::{field_access, impl_default, impl_display};
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
pub struct TopicLink {
text: String,
url: String,
}
impl TopicLink {
pub const fn new() -> Self {
Self {
text: String::new(),
url: String::new(),
}
}
}
field_access! {
TopicLink {
text: cow { str },
url: cow { str },
}
}
impl_default!(TopicLink);
impl_display!(TopicLink);
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_topic_link() {
let text = "topic link text";
let url = "http://topic.link.url";
let topic_link = TopicLink::new().with_text(text).with_url(url);
let topic_link_json = topic_link.to_string();
assert_eq!(topic_link.text(), text);
assert_eq!(topic_link.url(), url);
assert_eq!(serde_json::to_string(&topic_link).unwrap(), topic_link_json);
assert_eq!(
serde_json::from_str::<TopicLink>(&topic_link_json).unwrap(),
topic_link
);
}
}