HostDetails

Enum HostDetails 

Source
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

Source

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  (_)));
Source

pub fn from_ipv4_addr(addr: Ipv4Addr) -> Self

Gets the details of an Ipv4Addr host.

§Examples
use better_url::*;

assert!(matches!(HostDetails::from_ip_addr("127.0.0.1".parse().unwrap()), HostDetails::Ipv4(_)));
Source

pub fn from_ipv6_addr(addr: Ipv6Addr) -> Self

Gets the details of an Ipv6Addr host.

§Examples
use better_url::*;

assert!(matches!(HostDetails::from_ip_addr("::1".parse().unwrap()), HostDetails::Ipv6(_)));
Source

pub fn from_ip_addr(addr: IpAddr) -> Self

Gets the details of an IpAddr host.

§Examples
use better_url::*;

assert!(matches!(HostDetails::from_ip_addr("127.0.0.1".parse().unwrap()), HostDetails::Ipv4(_)));
assert!(matches!(HostDetails::from_ip_addr("::1"      .parse().unwrap()), HostDetails::Ipv6(_)));
Source

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  (_)));
Source

pub fn from_url(url: &Url) -> Option<Self>

Gets the details of a url::Url.

Source

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   ));
Source

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   ));
Source

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

Source§

fn clone(&self) -> HostDetails

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HostDetails

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<DomainDetails> for HostDetails

Source§

fn from(value: DomainDetails) -> Self

Converts to this type from the input type.
Source§

impl From<Ipv4Details> for HostDetails

Source§

fn from(value: Ipv4Details) -> Self

Converts to this type from the input type.
Source§

impl From<Ipv6Details> for HostDetails

Source§

fn from(value: Ipv6Details) -> Self

Converts to this type from the input type.
Source§

impl FromStr for HostDetails

Source§

type Err = ParseError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl PartialEq for HostDetails

Source§

fn eq(&self, other: &HostDetails) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<HostDetails> for DomainDetails

Source§

type Error = HostIsNotDomain

The type returned in the event of a conversion error.
Source§

fn try_from(value: HostDetails) -> Result<DomainDetails, Self::Error>

Performs the conversion.
Source§

impl TryFrom<HostDetails> for Ipv4Details

Source§

type Error = HostIsNotIpv4

The type returned in the event of a conversion error.
Source§

fn try_from(value: HostDetails) -> Result<Ipv4Details, Self::Error>

Performs the conversion.
Source§

impl TryFrom<HostDetails> for Ipv6Details

Source§

type Error = HostIsNotIpv6

The type returned in the event of a conversion error.
Source§

fn try_from(value: HostDetails) -> Result<Ipv6Details, Self::Error>

Performs the conversion.
Source§

impl Copy for HostDetails

Source§

impl Eq for HostDetails

Source§

impl StructuralPartialEq for HostDetails

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,