Explorar el Código

Add doc examples for `url::Url::username`.

Corey Farwell hace 10 años
padre
commit
2a7e0becfb
Se han modificado 1 ficheros con 12 adiciones y 0 borrados
  1. 12 0
      src/lib.rs

+ 12 - 0
src/lib.rs

@@ -447,6 +447,18 @@ impl Url {
 
     /// Return the username for this URL (typically the empty string)
     /// as a percent-encoded ASCII string.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use url::Url;
+    ///
+    /// let url = Url::parse("ftp://rms@example.com").unwrap();
+    /// assert_eq!(url.username(), "rms");
+    ///
+    /// let url = Url::parse("https://example.com").unwrap();
+    /// assert_eq!(url.username(), "");
+    /// ```
     pub fn username(&self) -> &str {
         if self.has_authority() {
             self.slice(self.scheme_end + ("://".len() as u32)..self.username_end)