Explorar o código

Auto merge of #268 - frewsxcv:path-segments, r=Ms2ger

Add doc examples for `url::Url::path_segments`.

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-url/268)
<!-- Reviewable:end -->
bors-servo %!s(int64=9) %!d(string=hai) anos
pai
achega
dc44ed0bbc
Modificáronse 1 ficheiros con 20 adicións e 0 borrados
  1. 20 0
      src/lib.rs

+ 20 - 0
src/lib.rs

@@ -813,6 +813,26 @@ impl Url {
     ///
     /// When `Some` is returned, the iterator always contains at least one string
     /// (which may be empty).
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use url::Url;
+    ///
+    /// let url = Url::parse("https://example.com/foo/bar").unwrap();
+    /// let mut path_segments = url.path_segments().unwrap();
+    /// assert_eq!(path_segments.next(), Some("foo"));
+    /// assert_eq!(path_segments.next(), Some("bar"));
+    /// assert_eq!(path_segments.next(), None);
+    ///
+    /// let url = Url::parse("https://example.com").unwrap();
+    /// let mut path_segments = url.path_segments().unwrap();
+    /// assert_eq!(path_segments.next(), Some(""));
+    /// assert_eq!(path_segments.next(), None);
+    ///
+    /// let url = Url::parse("data:text/plain,HelloWorld").unwrap();
+    /// assert!(url.path_segments().is_none());
+    /// ```
     pub fn path_segments(&self) -> Option<str::Split<char>> {
         let path = self.path();
         if path.starts_with('/') {