]> git.lizzy.rs Git - rust.git/blobdiff - src/libstd/path.rs
Rollup merge of #34475 - frewsxcv:path-component, r=GuillaumeGomez
[rust.git] / src / libstd / path.rs
index 8dc46239f3d036ebce0ca9844a534ba20c219df1..c103ff7f4b025345a260fd586f01eb01829b643e 100644 (file)
@@ -525,6 +525,26 @@ fn hash<H: Hasher>(&self, h: &mut H) {
 ///
 /// See the module documentation for an in-depth explanation of components and
 /// their role in the API.
+///
+/// This `enum` is created from iterating over the [`path::Components`]
+/// `struct`.
+///
+/// # Examples
+///
+/// ```rust
+/// use std::path::{Component, Path};
+///
+/// let path = Path::new("/tmp/foo/bar.txt");
+/// let components = path.components().collect::<Vec<_>>();
+/// assert_eq!(&components, &[
+///     Component::RootDir,
+///     Component::Normal("tmp".as_ref()),
+///     Component::Normal("foo".as_ref()),
+///     Component::Normal("bar.txt".as_ref()),
+/// ]);
+/// ```
+///
+/// [`path::Components`]: struct.Components.html
 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
 #[stable(feature = "rust1", since = "1.0.0")]
 pub enum Component<'a> {