1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//! A common API for getting and setting various parts of [`BetterHost`]s.
use serde::{Serialize, Deserialize};
use crate::types::*;
use crate::util::*;
/// A common API for getting various parts of [`BetterHost`]s.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Suitability)]
#[serde(deny_unknown_fields)]
pub enum HostPart {
/// [`BetterHost::host_str`].
Host,
/// [`BetterHost::normalized_host`].
NormalizedHost,
/// [`BetterHost::domain`].
Domain,
/// [`BetterHost::subdomain`].
Subdomain,
/// [`BetterHost::not_domain_suffix`].
NotDomainSuffix,
/// [`BetterHost::domain_middle`].
DomainMiddle,
/// [`BetterHost::reg_domain`].
RegDomain,
/// [`BetterHost::domain_suffix`].
DomainSuffix
}
impl HostPart {
/// Get the part.
pub fn get<'a>(&self, host: &'a BetterHost) -> Option<&'a str> {
match self {
Self::Host => Some(host.host_str()),
Self::NormalizedHost => Some(host.normalized_host()),
Self::Domain => host.domain(),
Self::Subdomain => host.subdomain(),
Self::NotDomainSuffix => host.not_domain_suffix(),
Self::DomainMiddle => host.domain_middle(),
Self::RegDomain => host.reg_domain(),
Self::DomainSuffix => host.domain_suffix()
}
}
}