Enum vimwiki::vendor::uriparse::authority::Host[]

pub enum Host<'host> {
    IPv4Address(Ipv4Addr),
    IPv6Address(Ipv6Addr),
    RegisteredName(RegisteredName<'host>),
}
Expand description

The host component of the authority as defined in [RFC3986, Section 3.2.2].

The RFC mentions support for future IP address literals. Of course, as of this moment there exist none, so hosts of the form "[v*...]" where '*' is a hexadecimal digit and '...' is the actual IP literal are not considered valid.

Also, the host is case-insensitive meaning that "example.com" and "ExAmPlE.CoM" refer to the same host. Furthermore, percent-encoding plays no role in equality checking for characters in the unreserved character set meaning that "example.com" and "ex%61mple.com" are identical. Both of these attributes are reflected in the equality and hash functions.

However, be aware that just because percent-encoding plays no role in equality checking does not mean that the host is normalized. If the host needs to be normalized, use the Host::normalize function.

Variants

IPv4Address(Ipv4Addr)

An IPv4 address. Based on the std’s implementation, leading zeros for octets are allowed for up to three digits. So for example, "000.000.000.000" is still considered a valid IPv4 address, but "000.000.000.0000" is not. Thus, it would be considered a registered name.

IPv6Address(Ipv6Addr)

An IPv6 address. This will always be encased in brackets ('[' and ']').

RegisteredName(RegisteredName<'host>)

Any other host that does not follow the syntax of an IP address. This includes even hosts of the form "999.999.999.999". One might expect this to produce an invalid IPv4 error, but the RFC states that it is a “first-match-wins” algorithm, and that host does not match the IPv4 literal syntax.

This may be changed in the future, since arguments can be made from either side.

Implementations

Returns a new host which is identical but has a lifetime tied to this host.

Converts the Host into an owned copy.

If you construct the host from a source with a non-static lifetime, you may run into lifetime problems due to the way the struct is designed. Calling this function will ensure that the returned value has a static lifetime.

This is different from just cloning. Cloning the host will just copy the references, and thus the lifetime will remain the same.

Returns whether the host is an IPv4 address.

Examples

use std::convert::TryFrom;

use uriparse::Host;

let host = Host::try_from("192.168.1.1").unwrap();
assert!(host.is_ipv4_address());

Returns whether the host is an IPv6 address.

Examples

use std::convert::TryFrom;

use uriparse::Host;

let host = Host::try_from("[::1]").unwrap();
assert!(host.is_ipv6_address());

Returns whether the host is normalized.

IPv4 and IPv6 hosts will always be normalized. Registered names are considered normalized if all characters are lowercase, no bytes that are in the unreserved character set are percent-encoded, and all alphabetical characters in percent-encodings are uppercase.

This function runs in constant-time.

Examples

use std::convert::TryFrom;

use uriparse::Host;

let host = Host::try_from("192.168.1.1").unwrap();
assert!(host.is_normalized());

let mut host = Host::try_from("EXAMPLE.COM").unwrap();
assert!(!host.is_normalized());
host.normalize();
assert!(host.is_normalized());

Returns whether the host is a registered name.

Examples

use std::convert::TryFrom;

use uriparse::Host;

let host = Host::try_from("example.com").unwrap();
assert!(host.is_registered_name());

Normalizes the host such that all characters are lowercase, no bytes that are in the unreserved character set are percent-encoded, and all alphabetical characters in percent-encodings are uppercase.

If the host is already normalized, the function will return immediately. Otherwise, if the host is not owned, this function will perform an allocation to clone it. The normalization itself though, is done in-place with no extra memory allocations required.

IPv4 and IPv6 hosts are always considered normalized.

Examples

use std::convert::TryFrom;

use uriparse::Host;

let mut host = Host::try_from("192.168.1.1").unwrap();
host.normalize();
assert_eq!(host.to_string(), "192.168.1.1");

let mut host = Host::try_from("%ff%41").unwrap();
assert_eq!(host.to_string(), "%ff%41");
host.normalize();
assert_eq!(host.to_string(), "%FFA");

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Serialize this value into the given Serde serializer. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Converts self into T using Into<T>. Read more

Converts self into a target type. Read more

Causes self to use its Binary implementation when Debug-formatted.

Causes self to use its Display implementation when Debug-formatted. Read more

Causes self to use its LowerExp implementation when Debug-formatted. Read more

Causes self to use its LowerHex implementation when Debug-formatted. Read more

Causes self to use its Octal implementation when Debug-formatted.

Causes self to use its Pointer implementation when Debug-formatted. Read more

Causes self to use its UpperExp implementation when Debug-formatted. Read more

Causes self to use its UpperHex implementation when Debug-formatted. Read more

Performs the conversion.

Performs the conversion.

Pipes by value. This is generally the method you want to use. Read more

Borrows self and passes that borrow into the pipe function. Read more

Mutably borrows self and passes that borrow into the pipe function. Read more

Borrows self, then passes self.borrow() into the pipe function. Read more

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more

Borrows self, then passes self.as_ref() into the pipe function.

Mutably borrows self, then passes self.as_mut() into the pipe function. Read more

Borrows self, then passes self.deref() into the pipe function.

Mutably borrows self, then passes self.deref_mut() into the pipe function. Read more

Pipes a value into a function that cannot ordinarily be called in suffix position. Read more

Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more

Pipes a trait mutable borrow into a function that cannot normally be called in suffix position. Read more

Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more

Pipes a trait mutable borrow into a function that cannot normally be called in suffix position. Read more

Pipes a dereference into a function that cannot normally be called in suffix position. Read more

Pipes a mutable dereference into a function that cannot normally be called in suffix position. Read more

Pipes a reference into a function that cannot ordinarily be called in suffix position. Read more

Pipes a mutable reference into a function that cannot ordinarily be called in suffix position. Read more

Immutable access to a value. Read more

Mutable access to a value. Read more

Immutable access to the Borrow<B> of a value. Read more

Mutable access to the BorrowMut<B> of a value. Read more

Immutable access to the AsRef<R> view of a value. Read more

Mutable access to the AsMut<R> view of a value. Read more

Immutable access to the Deref::Target of a value. Read more

Mutable access to the Deref::Target of a value. Read more

Calls .tap() only in debug builds, and is erased in release builds.

Calls .tap_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_borrow() only in debug builds, and is erased in release builds. Read more

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_ref() only in debug builds, and is erased in release builds. Read more

Calls .tap_ref_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_deref() only in debug builds, and is erased in release builds. Read more

Calls .tap_deref_mut() only in debug builds, and is erased in release builds. Read more

Provides immutable access for inspection. Read more

Calls tap in debug builds, and does nothing in release builds.

Provides mutable access for modification. Read more

Calls tap_mut in debug builds, and does nothing in release builds.

Provides immutable access to the reference for inspection.

Calls tap_ref in debug builds, and does nothing in release builds.

Provides mutable access to the reference for modification.

Calls tap_ref_mut in debug builds, and does nothing in release builds.

Provides immutable access to the borrow for inspection. Read more

Calls tap_borrow in debug builds, and does nothing in release builds.

Provides mutable access to the borrow for modification.

Calls tap_borrow_mut in debug builds, and does nothing in release builds. Read more

Immutably dereferences self for inspection.

Calls tap_deref in debug builds, and does nothing in release builds.

Mutably dereferences self for modification.

Calls tap_deref_mut in debug builds, and does nothing in release builds. Read more

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

Converts the given value to a String. Read more

Attempts to convert self into T using TryInto<T>. Read more

Attempts to convert self into a target type. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.