Explorar el Código

Add doc example for url::Url::port.

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

+ 12 - 0
src/lib.rs

@@ -560,6 +560,18 @@ impl Url {
     }
 
     /// Return the port number for this URL, if any.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use url::Url;
+    ///
+    /// let url = Url::parse("https://example.com").unwrap();
+    /// assert_eq!(url.port(), None);
+    ///
+    /// let url = Url::parse("ssh://example.com:22").unwrap();
+    /// assert_eq!(url.port(), Some(22));
+    /// ```
     #[inline]
     pub fn port(&self) -> Option<u16> {
         self.port