Debian Codegraph @

src/response/rir_search.rs

raw
1 //! RDAP RIR 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, autnum::Autnum, network::Network};
12
13 /// Represents RDAP IP search results as defined in RFC 9910 Section 4.2.
14 #[derive(Serialize, Deserialize, Clone, PartialEq, Debug, Eq)]
15 pub struct IpSearchResults {
16 #[serde(flatten)]
17 pub common: Common,
18
19 #[serde(rename = "ipSearchResults")]
20 pub results: Vec<Network>,
21 }
22
23 #[buildstructor::buildstructor]
24 impl IpSearchResults {
25 /// Builds an IP search result.
26 #[builder(entry = "response_obj", visibility = "pub")]
27 fn new_response_obj(results: Vec<Network>, extensions: Vec<Extension>) -> Self {
28 Self {
29 common: Common::level0().extensions(extensions).build(),
30 results,
31 }
32 }
33
34 /// Get the networks in the search.
35 pub fn results(&self) -> &[Network] {
36 self.results.as_ref()
37 }
38 }
39
40 impl CommonFields for IpSearchResults {
41 fn common(&self) -> &Common {
42 &self.common
43 }
44 }
45
46 impl ToResponse for IpSearchResults {
47 fn to_response(self) -> super::RdapResponse {
48 super::RdapResponse::IpSearchResults(Box::new(self))
49 }
50 }
51
52 impl ContentExtensions for IpSearchResults {
53 fn content_extensions(&self) -> std::collections::HashSet<super::ExtensionId> {
54 let mut exts = HashSet::new();
55 exts.insert(super::ExtensionId::IpSearchResults);
56 self.results()
57 .iter()
58 .for_each(|n| exts.extend(n.content_extensions()));
59 exts.extend(self.common().content_extensions());
60 exts
61 }
62 }
63
64 /// Represents RDAP autnum search results as defined in RFC 9910 Section 4.3.
65 #[derive(Serialize, Deserialize, Clone, PartialEq, Debug, Eq)]
66 pub struct AutnumSearchResults {
67 #[serde(flatten)]
68 pub common: Common,
69
70 #[serde(rename = "autnumSearchResults")]
71 pub results: Vec<Autnum>,
72 }
73
74 #[buildstructor::buildstructor]
75 impl AutnumSearchResults {
76 /// Builds an autnum search result.
77 #[builder(entry = "response_obj", visibility = "pub")]
78 fn new_response_obj(results: Vec<Autnum>, extensions: Vec<Extension>) -> Self {
79 Self {
80 common: Common::level0().extensions(extensions).build(),
81 results,
82 }
83 }
84
85 /// Get the autnums in the search.
86 pub fn results(&self) -> &[Autnum] {
87 self.results.as_ref()
88 }
89 }
90
91 impl CommonFields for AutnumSearchResults {
92 fn common(&self) -> &Common {
93 &self.common
94 }
95 }
96
97 impl ToResponse for AutnumSearchResults {
98 fn to_response(self) -> super::RdapResponse {
99 super::RdapResponse::AutnumSearchResults(Box::new(self))
100 }
101 }
102
103 impl ContentExtensions for AutnumSearchResults {
104 fn content_extensions(&self) -> std::collections::HashSet<super::ExtensionId> {
105 let mut exts = HashSet::new();
106 exts.insert(super::ExtensionId::AutnumSearchResults);
107 self.results()
108 .iter()
109 .for_each(|a| exts.extend(a.content_extensions()));
110 exts.extend(self.common().content_extensions());
111 exts
112 }
113 }