Skip to content

Commit

Permalink
Add Component examples
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Dec 3, 2016
1 parent 908dba0 commit 60d1660
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/libstd/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 60d1660

Please sign in to comment.