Explorar o código

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

Corey Farwell %!s(int64=10) %!d(string=hai) anos
pai
achega
f032633a7b
Modificáronse 1 ficheiros con 12 adicións e 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