1use crate::handle::{Handle, Handles};
4use crate::id::Id;
5use crate::servers::config::host_aliases::UrlPwa;
6
7#[derive(serde::Serialize, serde::Deserialize, Debug, Eq, PartialEq, Clone)]
9pub struct BasicInfo<UrlT = url::Url> {
10 pub handles: Handles,
14
15 pub name: String,
17
18 pub description: String,
21
22 pub url: UrlT,
25
26 pub id: Id,
28}
29
30impl From<BasicInfo<UrlPwa>> for BasicInfo {
31 fn from(hi: BasicInfo<UrlPwa>) -> Self {
32 Self {
33 url: hi.url.as_ref().clone(),
34 name: hi.name,
35 description: hi.description,
36 id: hi.id,
37 handles: hi.handles,
38 }
39 }
40}
41
42impl crate::map::Handled for BasicInfo {
43 fn handles(&self) -> &[Handle] {
44 &self.handles
45 }
46
47 fn id(&self) -> &Id {
48 &self.id
49 }
50}
51
52#[cfg(test)]
53mod tests {
54 use super::*;
55
56 #[test]
57 fn basic_info_serde() {
58 assert_eq!(
59 serde_json::from_str::<BasicInfo>(
60 r#"{"handles": [], "name": "Hub 1", "url": "https://example.com", "description": "some hub",
61 "id": "bLAPDnkcYj8S5hZ8NuH9OFTWKzypLqSakexoRvlZ_aA"}"#,
62 )
63 .unwrap_err()
64 .to_string(),
65 "must have at least one handle at line 1 column 14",
66 );
67 assert_eq!(
68 serde_json::from_str::<BasicInfo>(
69 r#"{"handles": ["hub_1"], "name": "Hub 1", "url": "https://example.com", "description": "some hub", "id": "bLAPDnkcYj8S5hZ8NuH9OFTWKzypLqSakexoRvlZ_aA"}"#,
70 )
71 .unwrap(),
72 BasicInfo{
73 handles: vec!["hub_1".parse().unwrap()].into(),
74 name: "Hub 1".to_string(),
75 url: "https://example.com".parse().unwrap(),
76 description: "some hub".to_string(),
77 id: "bLAPDnkcYj8S5hZ8NuH9OFTWKzypLqSakexoRvlZ_aA".parse().unwrap(),
78 }
79 );
80 }
81}