web_url/url/
host.rs

1use address::{DomainRef, HostRef};
2
3use crate::WebUrl;
4
5impl WebUrl {
6    //! Host
7
8    /// Gets the host reference.
9    pub fn host(&self) -> HostRef<'_> {
10        if let Some(ip) = self.ip {
11            HostRef::Address(ip)
12        } else {
13            HostRef::Name(unsafe { DomainRef::new(self.host_str()) })
14        }
15    }
16
17    /// Gets the host string.
18    ///
19    /// This will be a valid.
20    /// - If the host is a domain it will be lowercase.
21    /// - If the host is an IPv6 address it will include the '[]' brackets.
22    fn host_str(&self) -> &str {
23        let start: usize = (self.scheme_len + 3) as usize;
24        let end: usize = self.host_end as usize;
25        &self.url[start..end]
26    }
27}