Selaa lähdekoodia

Add doc examples for `Url::has_host`.

Corey Farwell 9 vuotta sitten
vanhempi
sitoutus
cc3ca7b89f
1 muutettua tiedostoa jossa 15 lisäystä ja 0 poistoa
  1. 15 0
      src/lib.rs

+ 15 - 0
src/lib.rs

@@ -595,6 +595,21 @@ impl Url {
     }
 
     /// Equivalent to `url.host().is_some()`.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use url::Url;
+    ///
+    /// let url = Url::parse("ftp://rms@example.com").unwrap();
+    /// assert!(url.has_host());
+    ///
+    /// let url = Url::parse("unix:/run/foo.socket").unwrap();
+    /// assert!(!url.has_host());
+    ///
+    /// let url = Url::parse("data:text/plain,Stuff").unwrap();
+    /// assert!(!url.has_host());
+    /// ```
     pub fn has_host(&self) -> bool {
         !matches!(self.host, HostInternal::None)
     }