pub enum HostDetails {
Domain(DomainDetails),
Ipv4(Ipv4Details),
Ipv6(Ipv6Details),
}Expand description
The details of a BetterUrl’s host.
Variants§
Domain(DomainDetails)
Details of a BetterUrl’s domain host.
Ipv4(Ipv4Details)
Details of a BetterUrl’s IPv4 host.
Ipv6(Ipv6Details)
Details of a BetterUrl’s IPv6 host.
Implementations§
Source§impl HostDetails
impl HostDetails
Sourcepub fn parse(host: &str) -> Result<Self, ParseError>
pub fn parse(host: &str) -> Result<Self, ParseError>
Gets the details of a host str.
§Errors
If the call to url::Host::parse returns an error, that error is returned.
§Examples
use better_url::*;
assert!(matches!(HostDetails::parse("example.com").unwrap(), HostDetails::Domain(_)));
assert!(matches!(HostDetails::parse("127.0.0.1" ).unwrap(), HostDetails::Ipv4 (_)));
assert!(matches!(HostDetails::parse("[::1]" ).unwrap(), HostDetails::Ipv6 (_)));Sourcepub fn from_ipv4_addr(addr: Ipv4Addr) -> Self
pub fn from_ipv4_addr(addr: Ipv4Addr) -> Self
Sourcepub fn from_ipv6_addr(addr: Ipv6Addr) -> Self
pub fn from_ipv6_addr(addr: Ipv6Addr) -> Self
Sourcepub fn from_ip_addr(addr: IpAddr) -> Self
pub fn from_ip_addr(addr: IpAddr) -> Self
Sourcepub fn from_host<T: AsRef<str>>(host: &Host<T>) -> Self
pub fn from_host<T: AsRef<str>>(host: &Host<T>) -> Self
Gets the details of a url::Host.
Assumes url::Host::Domain always contains valid domains, which isn’t true, but is true enough to work.
§Examples
use url::Host;
use better_url::*;
assert!(matches!(HostDetails::from_host(&Host::parse("example.com").unwrap()), HostDetails::Domain(_)));
assert!(matches!(HostDetails::from_host(&Host::parse("127.0.0.1" ).unwrap()), HostDetails::Ipv4 (_)));
assert!(matches!(HostDetails::from_host(&Host::parse("[::1]" ).unwrap()), HostDetails::Ipv6 (_)));Sourcepub fn domain_details(&self) -> Option<&DomainDetails>
pub fn domain_details(&self) -> Option<&DomainDetails>
If self is Self::Domain, return it.
§Examples
use better_url::*;
assert!(matches!(HostDetails::parse("example.com").unwrap().domain_details(), Some(_)));
assert!(matches!(HostDetails::parse("127.0.0.1" ).unwrap().domain_details(), None ));
assert!(matches!(HostDetails::parse("[::1]" ).unwrap().domain_details(), None ));Sourcepub fn ipv4_details(&self) -> Option<&Ipv4Details>
pub fn ipv4_details(&self) -> Option<&Ipv4Details>
If self is Self::Ipv4, return it.
§Examples
use better_url::*;
assert!(matches!(HostDetails::parse("example.com").unwrap().ipv4_details(), None ));
assert!(matches!(HostDetails::parse("127.0.0.1" ).unwrap().ipv4_details(), Some(_)));
assert!(matches!(HostDetails::parse("[::1]" ).unwrap().ipv4_details(), None ));Sourcepub fn ipv6_details(&self) -> Option<&Ipv6Details>
pub fn ipv6_details(&self) -> Option<&Ipv6Details>
If self is Self::Ipv6, return it.
§Examples
use better_url::*;
assert!(matches!(HostDetails::parse("example.com").unwrap().ipv6_details(), None ));
assert!(matches!(HostDetails::parse("127.0.0.1" ).unwrap().ipv6_details(), None ));
assert!(matches!(HostDetails::parse("[::1]" ).unwrap().ipv6_details(), Some(_)));Trait Implementations§
Source§impl Clone for HostDetails
impl Clone for HostDetails
Source§fn clone(&self) -> HostDetails
fn clone(&self) -> HostDetails
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for HostDetails
impl Debug for HostDetails
Source§impl From<DomainDetails> for HostDetails
impl From<DomainDetails> for HostDetails
Source§fn from(value: DomainDetails) -> Self
fn from(value: DomainDetails) -> Self
Converts to this type from the input type.
Source§impl From<Ipv4Details> for HostDetails
impl From<Ipv4Details> for HostDetails
Source§fn from(value: Ipv4Details) -> Self
fn from(value: Ipv4Details) -> Self
Converts to this type from the input type.
Source§impl From<Ipv6Details> for HostDetails
impl From<Ipv6Details> for HostDetails
Source§fn from(value: Ipv6Details) -> Self
fn from(value: Ipv6Details) -> Self
Converts to this type from the input type.
Source§impl FromStr for HostDetails
impl FromStr for HostDetails
Source§impl PartialEq for HostDetails
impl PartialEq for HostDetails
Source§impl TryFrom<HostDetails> for DomainDetails
impl TryFrom<HostDetails> for DomainDetails
Source§type Error = HostIsNotDomain
type Error = HostIsNotDomain
The type returned in the event of a conversion error.
Source§fn try_from(value: HostDetails) -> Result<DomainDetails, Self::Error>
fn try_from(value: HostDetails) -> Result<DomainDetails, Self::Error>
Performs the conversion.
Source§impl TryFrom<HostDetails> for Ipv4Details
impl TryFrom<HostDetails> for Ipv4Details
Source§type Error = HostIsNotIpv4
type Error = HostIsNotIpv4
The type returned in the event of a conversion error.
Source§fn try_from(value: HostDetails) -> Result<Ipv4Details, Self::Error>
fn try_from(value: HostDetails) -> Result<Ipv4Details, Self::Error>
Performs the conversion.
Source§impl TryFrom<HostDetails> for Ipv6Details
impl TryFrom<HostDetails> for Ipv6Details
Source§type Error = HostIsNotIpv6
type Error = HostIsNotIpv6
The type returned in the event of a conversion error.
Source§fn try_from(value: HostDetails) -> Result<Ipv6Details, Self::Error>
fn try_from(value: HostDetails) -> Result<Ipv6Details, Self::Error>
Performs the conversion.
impl Copy for HostDetails
impl Eq for HostDetails
impl StructuralPartialEq for HostDetails
Auto Trait Implementations§
impl Freeze for HostDetails
impl RefUnwindSafe for HostDetails
impl Send for HostDetails
impl Sync for HostDetails
impl Unpin for HostDetails
impl UnwindSafe for HostDetails
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more