[go: up one dir, main page]

Struct ProxyUrl

Source
pub struct ProxyUrl(/* private fields */);
Expand description

A wrapper for the proxy URL retrieved from the environment.

This struct will wrap the raw value of the URL, which is only guaranteed to be valid UTF-8 when returned. Various methods exist to extract the value as-is, translate it into other forms, and provide elements of interest.

Implementations§

Source§

impl ProxyUrl

Source

pub fn raw_value(self) -> Option<String>

Return the raw value of the proxy URL.

Source

pub fn is_none(self) -> bool

Return true if the None value is wrapped.

Source

pub fn with_default_port(self, port: u16) -> Self

Set the default port to use when transforming the raw URL value if the port isn’t specified in the URL.

A ProxyUrl instance returned by the library will have the default port set to 8080, which corresponds to http-alt in the IANA port registry. This is different from curl, which uses port 1080 as the default.

To skip the default port substitution, use [with_no_default_port()] (#method.with_no_default_port) on the instance.

Source

pub fn with_no_default_port(self) -> Self

Don’t use the default port value when transforming the raw URL.

Source

pub fn to_url(self) -> Option<Url>

Transform the raw proxy URL into a Url.

The transformation will:

  • Parse the raw URL as a Url. If the raw URL lacks the scheme, http is assumed and “http://” is prepended to canonicalize the value;
  • Ensure that the host part is not empty;
  • Use the default value for the port (or not, see with_default_port()) if one is not specified in the raw URL.
  • Ensure that the port is not empty.

If any of the steps fail, None will be returned.

Source

pub fn host_port(self) -> Option<(String, u16)>

Return the (host, port) tuple of the proxy.

The raw URL will first be transformed into a Url, with any errors in the conversion producing a None (see to_url()).

Source

pub fn to_string(self) -> Option<String>

Return the string representation of the proxy URL.

The raw URL will first be transformed into a Url, with any errors in the conversion producing a None (see to_url()).

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