|
@@ -423,6 +423,15 @@ impl Url {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// Return the scheme of this URL, lower-cased, as an ASCII string without the ':' delimiter.
|
|
/// Return the scheme of this URL, lower-cased, as an ASCII string without the ':' delimiter.
|
|
|
|
|
+ ///
|
|
|
|
|
+ /// # Examples
|
|
|
|
|
+ ///
|
|
|
|
|
+ /// ```
|
|
|
|
|
+ /// use url::Url;
|
|
|
|
|
+ ///
|
|
|
|
|
+ /// let url = Url::parse("file:///tmp/foo").unwrap();
|
|
|
|
|
+ /// assert_eq!(url.scheme(), "file");
|
|
|
|
|
+ /// ```
|
|
|
#[inline]
|
|
#[inline]
|
|
|
pub fn scheme(&self) -> &str {
|
|
pub fn scheme(&self) -> &str {
|
|
|
self.slice(..self.scheme_end)
|
|
self.slice(..self.scheme_end)
|
|
@@ -460,6 +469,9 @@ impl Url {
|
|
|
/// let url = Url::parse("ftp://rms@example.com").unwrap();
|
|
/// let url = Url::parse("ftp://rms@example.com").unwrap();
|
|
|
/// assert_eq!(url.username(), "rms");
|
|
/// assert_eq!(url.username(), "rms");
|
|
|
///
|
|
///
|
|
|
|
|
+ /// let url = Url::parse("ftp://:secret123@example.com").unwrap();
|
|
|
|
|
+ /// assert_eq!(url.username(), "");
|
|
|
|
|
+ ///
|
|
|
/// let url = Url::parse("https://example.com").unwrap();
|
|
/// let url = Url::parse("https://example.com").unwrap();
|
|
|
/// assert_eq!(url.username(), "");
|
|
/// assert_eq!(url.username(), "");
|
|
|
/// ```
|
|
/// ```
|
|
@@ -472,6 +484,24 @@ impl Url {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// Return the password for this URL, if any, as a percent-encoded ASCII string.
|
|
/// Return the password for this URL, if any, as a percent-encoded ASCII string.
|
|
|
|
|
+ ///
|
|
|
|
|
+ /// # Examples
|
|
|
|
|
+ ///
|
|
|
|
|
+ /// ```
|
|
|
|
|
+ /// use url::Url;
|
|
|
|
|
+ ///
|
|
|
|
|
+ /// let url = Url::parse("ftp://rms:secret123@example.com").unwrap();
|
|
|
|
|
+ /// assert_eq!(url.password(), Some("secret123"));
|
|
|
|
|
+ ///
|
|
|
|
|
+ /// let url = Url::parse("ftp://:secret123@example.com").unwrap();
|
|
|
|
|
+ /// assert_eq!(url.password(), Some("secret123"));
|
|
|
|
|
+ ///
|
|
|
|
|
+ /// let url = Url::parse("ftp://rms@example.com").unwrap();
|
|
|
|
|
+ /// assert_eq!(url.password(), None);
|
|
|
|
|
+ ///
|
|
|
|
|
+ /// let url = Url::parse("https://example.com").unwrap();
|
|
|
|
|
+ /// assert_eq!(url.password(), None);
|
|
|
|
|
+ /// ```
|
|
|
pub fn password(&self) -> Option<&str> {
|
|
pub fn password(&self) -> Option<&str> {
|
|
|
// This ':' is not the one marking a port number since a host can not be empty.
|
|
// This ':' is not the one marking a port number since a host can not be empty.
|
|
|
// (Except for file: URLs, which do not have port numbers.)
|
|
// (Except for file: URLs, which do not have port numbers.)
|