Rollup merge of #38141 - GuillaumeGomez:component_doc, r=frewsxcv

Add Component examples

r? @frewsxcv
This commit is contained in:
Corey Farwell 2016-12-03 15:39:54 -05:00 committed by GitHub
commit 2e038ed3de

View 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 {