From 60d1660748b30e2f3c69738e068d252271715268 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 2 Dec 2016 20:16:12 -0800 Subject: [PATCH] Add Component examples --- src/libstd/path.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/libstd/path.rs b/src/libstd/path.rs index d215f368d1e66..d13baea40a9ff 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -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 {