]> git.lizzy.rs Git - rust.git/commitdiff
Add Component examples
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Sat, 3 Dec 2016 04:16:12 +0000 (20:16 -0800)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Sat, 3 Dec 2016 04:16:12 +0000 (20:16 -0800)
src/libstd/path.rs

index d215f368d1e66a5e650ce41b5412fcc4e59e787c..d13baea40a9ff8069744f6a278548ac468ddee8d 100644 (file)
@@ -457,7 +457,17 @@ pub enum Component<'a> {
 }
 
 impl<'a> Component<'a> {
-    /// Extracts the underlying `OsStr` slice
+    /// Extracts the underlying `OsStr` slice.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use std::path::Path;
+    ///
+    /// let path = Path::new("./tmp/foo/bar.txt");
+    /// let components: Vec<_> = path.components().map(|comp| comp.as_os_str()).collect();
+    /// assert_eq!(&components, &[".", "tmp", "foo", "bar.txt"]);
+    /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
     pub fn as_os_str(self) -> &'a OsStr {
         match self {