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
45
46
47
48
49
50
51
52
//! Fqddot stuff.
use crate::prelude::*;
impl BetterUrl {
/// If it has a domain FQDdot.
pub fn has_fqddot(&self) -> bool {
self.domain_details().is_some_and(DomainHostDetails::is_fqdn)
}
/// If the host is a fully qualified domain name.
pub fn is_fqdn(&self) -> bool {
self.domain_details().is_some_and(DomainHostDetails::is_fqdn)
}
/// The [`Range`] of the domain FQDdot.
fn domain_fqddot_thing(&self) -> Option<Range<usize>> {
let ha = self.host_after ()?;
let dd = self.domain_details()?;
match dd.is_fqdn() {
false => None,
true => Some(ha - 1 .. ha),
}
}
/// The FQDDot as a [`str`].
pub fn fqddot_str(&self) -> Option<&str> {
Some(unsafe {self.as_str().get_unchecked(self.domain_fqddot_thing()?)})
}
/// [`DomainHost::set_fqdn`].
/// # Errors
/// If [`Self::domain`] returns [`None`], returns the error [`NoDomain`].
///
/// If [`DomainHost::set_fqdn`] returns an error, that error is returned.
///
/// If [`Self::set_host`] returns an error, that error is returned.
pub fn set_fqdn(&mut self, value: bool) -> Result<bool, SetHostError> {
if self.domain_details().ok_or(NoDomain)?.is_fqdn() != value {
let mut domain = self.domain().ok_or(NoDomain)?;
domain.set_fqdn(value)?;
self.set_host(domain.into_owned())?;
Ok(true)
} else {
Ok(false)
}
}
}