Explorar o código

Add doc examples for `Url::has_host`.

Corey Farwell %!s(int64=9) %!d(string=hai) anos
pai
achega
cc3ca7b89f
Modificáronse 1 ficheiros con 15 adicións e 0 borrados
  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)
     }