Selaa lähdekoodia

Add doc example for `url::Url::join`.

Corey Farwell 10 vuotta sitten
vanhempi
sitoutus
d0ab24777b
1 muutettua tiedostoa jossa 20 lisäystä ja 0 poistoa
  1. 20 0
      src/lib.rs

+ 20 - 0
src/lib.rs

@@ -234,6 +234,26 @@ impl Url {
     }
 
     /// Parse a string as an URL, with this URL as the base URL.
+    ///
+    /// # Examples
+    ///
+    /// ```rust
+    /// use url::Url;
+    ///
+    /// let url = Url::parse("https://example.net").unwrap();
+    /// let url = url.join("foo").unwrap();
+    /// assert_eq!(url.as_str(), "https://example.net/foo");
+    /// ```
+    ///
+    /// Trailing slashes are not preserved:
+    ///
+    /// ```rust
+    /// use url::Url;
+    ///
+    /// let url = Url::parse("https://example.net/foo/").unwrap();
+    /// let url = url.join("bar").unwrap();
+    /// assert_eq!(url.as_str(), "https://example.net/foo/bar");
+    /// ```
     #[inline]
     pub fn join(&self, input: &str) -> Result<Url, ::ParseError> {
         Url::options().base_url(Some(self)).parse(input)