Skip to content

Commit f1d600c

Browse files
committed
Expand std::path::Component documentation.
Indicate how it gets created and add an example.
1 parent 35004b4 commit f1d600c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/libstd/path.rs

+20
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,26 @@ impl<'a> Hash for PrefixComponent<'a> {
525525
///
526526
/// See the module documentation for an in-depth explanation of components and
527527
/// their role in the API.
528+
///
529+
/// This `enum` is created from iterating over the [`path::Components`]
530+
/// `struct`.
531+
///
532+
/// # Examples
533+
///
534+
/// ```rust
535+
/// use std::path::{Component, Path};
536+
///
537+
/// let path = Path::new("/tmp/foo/bar.txt");
538+
/// let components = path.components().collect::<Vec<_>>();
539+
/// assert_eq!(&components, &[
540+
/// Component::RootDir,
541+
/// Component::Normal("tmp".as_ref()),
542+
/// Component::Normal("foo".as_ref()),
543+
/// Component::Normal("bar.txt".as_ref()),
544+
/// ]);
545+
/// ```
546+
///
547+
/// [`path::Components`]: struct.Components.html
528548
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
529549
#[stable(feature = "rust1", since = "1.0.0")]
530550
pub enum Component<'a> {

0 commit comments

Comments
 (0)