@@ -1882,6 +1882,19 @@ impl FromStr for PathBuf {
1882
1882
1883
1883
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1884
1884
impl < P : AsRef < Path > > FromIterator < P > for PathBuf {
1885
+ /// Creates a new `PathBuf` from the [`Path`] elements of an iterator.
1886
+ ///
1887
+ /// This uses [`push`](Self::push) to add each element, so can be used to adjoin multiple path
1888
+ /// [components](Components).
1889
+ ///
1890
+ /// # Examples
1891
+ /// ```
1892
+ /// # use std::path::PathBuf;
1893
+ /// let path = PathBuf::from_iter(["/tmp", "foo", "bar"]);
1894
+ /// assert_eq!(path, PathBuf::from("/tmp/foo/bar"));
1895
+ /// ```
1896
+ ///
1897
+ /// See documentation for [`push`](Self::push) for more details on how the path is constructed.
1885
1898
fn from_iter < I : IntoIterator < Item = P > > ( iter : I ) -> PathBuf {
1886
1899
let mut buf = PathBuf :: new ( ) ;
1887
1900
buf. extend ( iter) ;
@@ -1891,6 +1904,19 @@ impl<P: AsRef<Path>> FromIterator<P> for PathBuf {
1891
1904
1892
1905
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1893
1906
impl < P : AsRef < Path > > Extend < P > for PathBuf {
1907
+ /// Extends `self` with [`Path`] elements from `iter`.
1908
+ ///
1909
+ /// This uses [`push`](Self::push) to add each element, so can be used to adjoin multiple path [components](Components).
1910
+ ///
1911
+ /// # Examples
1912
+ /// ```
1913
+ /// # use std::path::PathBuf;
1914
+ /// let mut path = PathBuf::from("/tmp");
1915
+ /// path.extend(["foo", "bar", "file.txt"]);
1916
+ /// assert_eq!(path, PathBuf::from("/tmp/foo/bar/file.txt"));
1917
+ /// ```
1918
+ ///
1919
+ /// See documentation for [`push`](Self::push) for more details on how the path is constructed.
1894
1920
fn extend < I : IntoIterator < Item = P > > ( & mut self , iter : I ) {
1895
1921
iter. into_iter ( ) . for_each ( move |p| self . push ( p. as_ref ( ) ) ) ;
1896
1922
}
0 commit comments