pub struct HttpUrlComponents {
pub protocol: Protocol,
pub host: Option<String>,
pub port: Option<u16>,
pub path: Option<String>,
pub query: Option<String>,
pub fragment: Option<String>,
}
Expand description
A struct representing a parsed URL with various components.
This struct is used to store the different components of a URL, such as the scheme, username, password, host, port, path, query, and fragment. It allows for easy handling and manipulation of URL data.
§Fields
scheme
: The URL scheme (e.g., “http”, “https”) as a string, orNone
if not specified.host
: The host portion of the URL (e.g., “example.com”), orNone
if not specified.port
: The port number, if specified, orNone
if not specified.path
: The path portion of the URL (e.g., “/path/to/resource”), orNone
if not specified.query
: The query string, if present, orNone
if not specified.fragment
: The fragment identifier, if present, orNone
if not specified.
This struct is primarily used for holding the components of a URL after parsing, allowing for easy manipulation and access to the individual components.
Fields§
§protocol: Protocol
§host: Option<String>
§port: Option<u16>
§path: Option<String>
§query: Option<String>
§fragment: Option<String>
Implementations§
Source§impl HttpUrlComponents
impl HttpUrlComponents
Sourcepub fn parse(url_str: &str) -> Result<Self, Error>
pub fn parse(url_str: &str) -> Result<Self, Error>
Parses a URL string into a HttpUrlComponents
instance.
This method attempts to parse a given URL string into its components such as
scheme, username, password, host, port, path, query, and fragment. If the URL
is invalid, it returns an Error::InvalidUrl
error.
§Parameters
url_str
: A string slice representing the URL to be parsed.
§Returns
Returns a Result
containing either a HttpUrlComponents
instance populated with the
parsed components or an Error::InvalidUrl
if the parsing fails.
Trait Implementations§
Source§impl Clone for HttpUrlComponents
impl Clone for HttpUrlComponents
Source§fn clone(&self) -> HttpUrlComponents
fn clone(&self) -> HttpUrlComponents
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more