diff options
| author | Yotam Ofek <yotam.ofek@gmail.com> | 2025-06-09 09:21:33 +0000 |
|---|---|---|
| committer | Yotam Ofek <yotam.ofek@gmail.com> | 2025-06-16 07:49:27 +0000 |
| commit | 45bbb3dfbfe2cb3009580c2ad42e0ce53226b649 (patch) | |
| tree | 1fecbea26c604311b6080476abb9d01db0847a54 /library/std/src/path.rs | |
| parent | 68ac5abb067806a88464ddbfbd3c7eec877b488d (diff) | |
| download | rust-45bbb3dfbfe2cb3009580c2ad42e0ce53226b649.tar.gz rust-45bbb3dfbfe2cb3009580c2ad42e0ce53226b649.zip | |
Add documentation for `PathBuf`'s `FromIterator` and `Extend` impls
Diffstat (limited to 'library/std/src/path.rs')
| -rw-r--r-- | library/std/src/path.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/library/std/src/path.rs b/library/std/src/path.rs index 826d9f0f39d..0469db0814c 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -1882,6 +1882,19 @@ impl FromStr for PathBuf { #[stable(feature = "rust1", since = "1.0.0")] impl<P: AsRef<Path>> FromIterator<P> for PathBuf { + /// Creates a new `PathBuf` from the [`Path`] elements of an iterator. + /// + /// This uses [`push`](Self::push) to add each element, so can be used to adjoin multiple path + /// [components](Components). + /// + /// # Examples + /// ``` + /// # use std::path::PathBuf; + /// let path = PathBuf::from_iter(["/tmp", "foo", "bar"]); + /// assert_eq!(path, PathBuf::from("/tmp/foo/bar")); + /// ``` + /// + /// See documentation for [`push`](Self::push) for more details on how the path is constructed. fn from_iter<I: IntoIterator<Item = P>>(iter: I) -> PathBuf { let mut buf = PathBuf::new(); buf.extend(iter); @@ -1891,6 +1904,20 @@ impl<P: AsRef<Path>> FromIterator<P> for PathBuf { #[stable(feature = "rust1", since = "1.0.0")] impl<P: AsRef<Path>> Extend<P> for PathBuf { + /// Extends `self` with [`Path`] elements from `iter`. + /// + /// This uses [`push`](Self::push) to add each element, so can be used to adjoin multiple path + /// [components](Components). + /// + /// # Examples + /// ``` + /// # use std::path::PathBuf; + /// let mut path = PathBuf::from("/tmp"); + /// path.extend(["foo", "bar", "file.txt"]); + /// assert_eq!(path, PathBuf::from("/tmp/foo/bar/file.txt")); + /// ``` + /// + /// See documentation for [`push`](Self::push) for more details on how the path is constructed. fn extend<I: IntoIterator<Item = P>>(&mut self, iter: I) { iter.into_iter().for_each(move |p| self.push(p.as_ref())); } |
