Struct lychee_lib::Uri

source ·
pub struct Uri { /* private fields */ }
Expand description

Lychee’s own representation of a URI, which encapsulates all supported formats.

If the scheme is mailto, it’s a mail address. Otherwise it’s treated as a website URL.

Implementations§

source§

impl Uri

source

pub fn as_str(&self) -> &str

Returns the string representation of the Uri.

If it’s an email address, returns the string with scheme stripped. Otherwise returns the string as-is.

source

pub fn scheme(&self) -> &str

Returns the scheme of the URI (e.g. http or mailto)

source

pub fn domain(&self) -> Option<&str>

Returns the domain of the URI (e.g. example.com)

source

pub fn path(&self) -> &str

Returns the path of the URI (e.g. /path/to/resource)

source

pub fn path_segments(&self) -> Option<Split<'_, char>>

Unless this URL is cannot-be-a-base, return an iterator of ‘/’ slash-separated path segments, each as a percent-encoded ASCII string.

Return None for cannot-be-a-base URLs.

source

pub fn host_ip(&self) -> Option<IpAddr>

Returns the IP address (either IPv4 or IPv6) of the URI, or None if it is a domain

source

pub fn is_mail(&self) -> bool

Check if the URI is a valid mail address

source

pub fn is_file(&self) -> bool

Check if the URI is a file

source

pub fn is_data(&self) -> bool

Check if the URI is a data URI

source

pub fn is_loopback(&self) -> bool

Returns true if this is a loopback address.

§IPv4

This is a loopback address (127.0.0.0/8).

This property is defined by IETF RFC 1122.

§IPv6

This is the loopback address (::1), as defined in IETF RFC 4291 section 2.5.3.

source

pub fn is_private(&self) -> bool

Returns true if this is a private IPv4 address, a unique local IPv6 address (fc00::/7).

§IPv4

The private address ranges are defined in IETF RFC 1918 and include:

  • 10.0.0.0/8
  • 172.16.0.0/12
  • 192.168.0.0/16
§IPv6

Unique local address is defined in IETF RFC 4193.

§Note

Unicast site-local network was defined in IETF RFC 4291, but was fully deprecated in IETF RFC 3879. So it is NOT considered as private on this purpose.

Returns true if the address is a link-local IPv4 address (169.254.0.0/16), or an IPv6 unicast address with link-local scope (fe80::/10).

§IPv4

Link-local address is defined by IETF RFC 3927.

§IPv6

Unicast address with link-local scope is defined in IETF RFC 4291.

Trait Implementations§

source§

impl AsRef<str> for Uri

source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Clone for Uri

source§

fn clone(&self) -> Uri

Returns a copy 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 Uri

source§

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

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

impl<'de> Deserialize<'de> for Uri

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Uri

source§

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

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

impl From<Url> for Uri

source§

fn from(url: Url) -> Self

Converts to this type from the input type.
source§

impl Hash for Uri

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

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

impl Ord for Uri

source§

fn cmp(&self, other: &Uri) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Uri

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Uri

source§

fn partial_cmp(&self, other: &Uri) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for Uri

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl TryFrom<&str> for Uri

source§

fn try_from(s: &str) -> Result<Self>

Create a new URI from a string

Note: We do not handle relative URLs here, as we do not know the base URL. Furthermore paths also cannot be resolved, as we do not know the file system.

§Errors

Returns an error if the string is not a valid URI

§

type Error = ErrorKind

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

impl TryFrom<String> for Uri

§

type Error = ErrorKind

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

fn try_from(s: String) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<Uri> for Request

§

type Error = ErrorKind

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

fn try_from(uri: Uri) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Eq for Uri

source§

impl StructuralPartialEq for Uri

Auto Trait Implementations§

§

impl Freeze for Uri

§

impl RefUnwindSafe for Uri

§

impl Send for Uri

§

impl Sync for Uri

§

impl Unpin for Uri

§

impl UnwindSafe for Uri

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<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> FromResponse for T

source§

fn from_response<'async_trait, B>( response: Response<B> ) -> Pin<Box<dyn Future<Output = Result<T, Error>> + Send + 'async_trait>>
where B: Body<Data = Bytes, Error = Error> + Send + 'async_trait, T: 'async_trait,

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

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

source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T> ToStringFallible for T
where T: Display,

source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

source§

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

§

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>,

§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,