| 1 |
//! Server Help Response. |
| 2 |
use std::collections::HashSet; |
| 3 |
|
| 4 |
use crate::prelude::{ContentExtensions, ExtensionId}; |
| 5 |
|
| 6 |
use { |
| 7 |
crate::prelude::{Extension, Notice}, |
| 8 |
serde::{Deserialize, Serialize}, |
| 9 |
}; |
| 10 |
|
| 11 |
use super::{Common, CommonFields, ToResponse, to_opt_vec}; |
| 12 |
|
| 13 |
/// Represents an RDAP help response. |
| 14 |
/// |
| 15 |
/// Use the builders to create one: |
| 16 |
/// ```rust |
| 17 |
/// use icann_rdap_common::prelude::*; |
| 18 |
/// |
| 19 |
/// let e = Help::response() |
| 20 |
/// .build(); |
| 21 |
/// ``` |
| 22 |
/// |
| 23 |
/// Use the getter functions to access information. |
| 24 |
/// See [CommonFields] for common getter functions. |
| 25 |
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] |
| 26 |
pub struct Help { |
| 27 |
#[serde(flatten)] |
| 28 |
pub common: Common, |
| 29 |
} |
| 30 |
|
| 31 |
#[buildstructor::buildstructor] |
| 32 |
impl Help { |
| 33 |
/// Builds a basic help response. |
| 34 |
#[builder(entry = "response", visibility = "pub")] |
| 35 |
fn new_response(notices: Vec<Notice>, extensions: Vec<Extension>) -> Self { |
| 36 |
Self { |
| 37 |
common: Common::level0() |
| 38 |
.extensions(extensions) |
| 39 |
.and_notices(to_opt_vec(notices)) |
| 40 |
.build(), |
| 41 |
} |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
impl CommonFields for Help { |
| 46 |
fn common(&self) -> &Common { |
| 47 |
&self.common |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
impl ToResponse for Help { |
| 52 |
fn to_response(self) -> super::RdapResponse { |
| 53 |
super::RdapResponse::Help(Box::new(self)) |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
impl ContentExtensions for Help { |
| 58 |
fn content_extensions(&self) -> std::collections::HashSet<super::ExtensionId> { |
| 59 |
let mut exts = HashSet::new(); |
| 60 |
exts.extend(self.common().content_extensions()); |
| 61 |
exts.insert(ExtensionId::Cidr0); |
| 62 |
exts.insert(ExtensionId::JsContact); |
| 63 |
exts.insert(ExtensionId::Redacted); |
| 64 |
exts.insert(ExtensionId::SimpleRedaction); |
| 65 |
exts.insert(ExtensionId::Ttl0); |
| 66 |
exts.insert(ExtensionId::Rpki1); |
| 67 |
exts |
| 68 |
} |
| 69 |
} |