Debian Codegraph @

src/response/search.rs

raw
1 //! RDAP Search Results.
2 use std::collections::HashSet;
3
4 use crate::prelude::ContentExtensions;
5
6 use {
7 crate::prelude::{Common, Extension},
8 serde::{Deserialize, Serialize},
9 };
10
11 use super::{CommonFields, ToResponse, domain::Domain, entity::Entity, nameserver::Nameserver};
12
13 /// Represents RDAP domain search results.
14 #[derive(Serialize, Deserialize, Clone, PartialEq, Debug, Eq)]
15 pub struct DomainSearchResults {
16 #[serde(flatten)]
17 pub common: Common,
18
19 #[serde(rename = "domainSearchResults")]
20 pub results: Vec<Domain>,
21 }
22
23 #[buildstructor::buildstructor]
24 impl DomainSearchResults {
25 /// Builds a domain search result.
26 #[builder(entry = "response_obj", visibility = "pub")]
27 fn new_response_obj(results: Vec<Domain>, extensions: Vec<Extension>) -> Self {
28 Self {
29 common: Common::level0().extensions(extensions).build(),
30 results,
31 }
32 }
33
34 /// Get the domains in the search.
35 pub fn results(&self) -> &[Domain] {
36 self.results.as_ref()
37 }
38 }
39
40 impl CommonFields for DomainSearchResults {
41 fn common(&self) -> &Common {
42 &self.common
43 }
44 }
45
46 impl ToResponse for DomainSearchResults {
47 fn to_response(self) -> super::RdapResponse {
48 super::RdapResponse::DomainSearchResults(Box::new(self))
49 }
50 }
51
52 impl ContentExtensions for DomainSearchResults {
53 fn content_extensions(&self) -> std::collections::HashSet<super::ExtensionId> {
54 let mut exts = HashSet::new();
55 self.results()
56 .iter()
57 .for_each(|d| exts.extend(d.content_extensions()));
58 exts.extend(self.common().content_extensions());
59 exts
60 }
61 }
62
63 /// Represents RDAP nameserver search results.
64 #[derive(Serialize, Deserialize, Clone, PartialEq, Debug, Eq)]
65 pub struct NameserverSearchResults {
66 #[serde(flatten)]
67 pub common: Common,
68
69 #[serde(rename = "nameserverSearchResults")]
70 pub results: Vec<Nameserver>,
71 }
72
73 #[buildstructor::buildstructor]
74 impl NameserverSearchResults {
75 /// Builds a nameserver search result.
76 #[builder(entry = "response_obj", visibility = "pub")]
77 fn new_response_obj(results: Vec<Nameserver>, extensions: Vec<Extension>) -> Self {
78 Self {
79 common: Common::level0().extensions(extensions).build(),
80 results,
81 }
82 }
83
84 /// Get the nameservers in the search.
85 pub fn results(&self) -> &[Nameserver] {
86 self.results.as_ref()
87 }
88 }
89
90 impl CommonFields for NameserverSearchResults {
91 fn common(&self) -> &Common {
92 &self.common
93 }
94 }
95
96 impl ToResponse for NameserverSearchResults {
97 fn to_response(self) -> super::RdapResponse {
98 super::RdapResponse::NameserverSearchResults(Box::new(self))
99 }
100 }
101
102 impl ContentExtensions for NameserverSearchResults {
103 fn content_extensions(&self) -> std::collections::HashSet<super::ExtensionId> {
104 let mut exts = HashSet::new();
105 self.results()
106 .iter()
107 .for_each(|n| exts.extend(n.content_extensions()));
108 exts.extend(self.common().content_extensions());
109 exts
110 }
111 }
112
113 /// Represents RDAP entity search results.
114 #[derive(Serialize, Deserialize, Clone, PartialEq, Debug, Eq)]
115 pub struct EntitySearchResults {
116 #[serde(flatten)]
117 pub common: Common,
118
119 #[serde(rename = "entitySearchResults")]
120 pub results: Vec<Entity>,
121 }
122
123 #[buildstructor::buildstructor]
124 impl EntitySearchResults {
125 /// Builds an entity search result.
126 #[builder(entry = "response_obj", visibility = "pub")]
127 fn new_response_obj(results: Vec<Entity>, extensions: Vec<Extension>) -> Self {
128 Self {
129 common: Common::level0().extensions(extensions).build(),
130 results,
131 }
132 }
133
134 /// Get the entities in the search.
135 pub fn results(&self) -> &[Entity] {
136 self.results.as_ref()
137 }
138 }
139
140 impl CommonFields for EntitySearchResults {
141 fn common(&self) -> &Common {
142 &self.common
143 }
144 }
145
146 impl ToResponse for EntitySearchResults {
147 fn to_response(self) -> super::RdapResponse {
148 super::RdapResponse::EntitySearchResults(Box::new(self))
149 }
150 }
151
152 impl ContentExtensions for EntitySearchResults {
153 fn content_extensions(&self) -> std::collections::HashSet<super::ExtensionId> {
154 let mut exts = HashSet::new();
155 self.results()
156 .iter()
157 .for_each(|e| exts.extend(e.content_extensions()));
158 exts.extend(self.common().content_extensions());
159 exts
160 }
161 }