Skip to content

Commit 2e038ed

Browse files
authored
Rollup merge of #38141 - GuillaumeGomez:component_doc, r=frewsxcv
Add Component examples r? @frewsxcv
2 parents 02ad965 + 60d1660 commit 2e038ed

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/libstd/path.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,17 @@ pub enum Component<'a> {
457457
}
458458

459459
impl<'a> Component<'a> {
460-
/// Extracts the underlying `OsStr` slice
460+
/// Extracts the underlying `OsStr` slice.
461+
///
462+
/// # Examples
463+
///
464+
/// ```
465+
/// use std::path::Path;
466+
///
467+
/// let path = Path::new("./tmp/foo/bar.txt");
468+
/// let components: Vec<_> = path.components().map(|comp| comp.as_os_str()).collect();
469+
/// assert_eq!(&components, &[".", "tmp", "foo", "bar.txt"]);
470+
/// ```
461471
#[stable(feature = "rust1", since = "1.0.0")]
462472
pub fn as_os_str(self) -> &'a OsStr {
463473
match self {

0 commit comments

Comments
 (0)