Ver Fonte

Add doc examples for `Url::has_host`.

Corey Farwell há 9 anos atrás
pai
commit
cc3ca7b89f
1 ficheiros alterados com 15 adições e 0 exclusões
  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)
     }