Browse Source

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

Corey Farwell 10 years ago
parent
commit
f032633a7b
1 changed files with 12 additions and 0 deletions
  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.
     /// 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]
     #[inline]
     pub fn port(&self) -> Option<u16> {
     pub fn port(&self) -> Option<u16> {
         self.port
         self.port