Struct url::RelativeSchemeData [] [src]

pub struct RelativeSchemeData {
    pub username: String,
    pub password: Option<String>,
    pub host: Host,
    pub port: Option<u16>,
    pub default_port: Option<u16>,
    pub path: Vec<String>,
}

Components for URLs in a relative scheme such as HTTP.

Fields

username

The username of the URL, as a possibly empty, percent-encoded string.

Percent encoded strings are within the ASCII range.

See also the lossy_percent_decode_username method.

password

The password of the URL.

None if the : delimiter character was not part of the parsed input, otherwise a possibly empty, percent-encoded string.

Percent encoded strings are within the ASCII range.

See also the lossy_percent_decode_password method.

host

The host of the URL, either a domain name or an IPv4 address

port

The port number of the URL. None for file-like schemes, or to indicate the default port number.

default_port

The default port number for the URL’s scheme. None for file-like schemes.

path

The path of the URL, as vector of percent-encoded strings.

Percent encoded strings are within the ASCII range.

See also the serialize_path method and, for URLs in the file scheme, the to_file_path method.

Methods

impl RelativeSchemeData

fn lossy_percent_decode_username(&self) -> String

Percent-decode the URL’s username.

This is “lossy”: invalid UTF-8 percent-encoded byte sequences will be replaced � U+FFFD, the replacement character.

fn lossy_percent_decode_password(&self) -> Option<String>

Percent-decode the URL’s password, if any.

This is “lossy”: invalid UTF-8 percent-encoded byte sequences will be replaced � U+FFFD, the replacement character.

fn to_file_path(&self) -> Result<PathBuf, ()>

Assuming the URL is in the file scheme or similar, convert its path to an absolute std::path::Path.

Note: This does not actually check the URL’s scheme, and may give nonsensical results for other schemes. It is the user’s responsibility to check the URL’s scheme before calling this.

The return type (when Ok()) is generic and can be either std::path::posix::Path or std::path::windows::Path. (Use std::path::Path to pick one of them depending on the local system.) If the compiler can not infer the desired type from context, you may have to specifiy it:

let path = url.to_file_path::<std::path::posix::Path>();

Returns Err if the host is neither empty nor "localhost", or if Path::new_opt() returns None. (That is, if the percent-decoded path contains a NUL byte or, for a Windows path, is not UTF-8.)

fn domain<'a>(&'a self) -> Option<&'a str>

If the host is a domain, return the domain as a string.

fn domain_mut<'a>(&'a mut self) -> Option<&'a mut String>

If the host is a domain, return a mutable reference to the domain string.

fn port_or_default(&self) -> Option<u16>

Return the port number of the URL, even if it is the default. Return None for file-like URLs.

fn serialize_path(&self) -> String

Serialize the path as a string.

The returned string starts with a "/" slash, and components are separated by slashes. A trailing slash represents an empty last component.

fn serialize_userinfo(&self) -> String

Serialize the userinfo as a string.

Format: ":@".

Trait Implementations

impl PartialEq for RelativeSchemeData

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

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

impl Eq for RelativeSchemeData

impl Hash for RelativeSchemeData

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

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

impl PartialOrd for RelativeSchemeData

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

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

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

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

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

impl Ord for RelativeSchemeData

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

impl Display for RelativeSchemeData

fn fmt(&self, formatter: &mut Formatter) -> Result

Derived Implementations

impl Debug for RelativeSchemeData

fn fmt(&self, __arg_0: &mut Formatter) -> Result

impl Clone for RelativeSchemeData

fn clone(&self) -> RelativeSchemeData

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