diff --git a/src/path/mod.rs b/src/path/mod.rs index e9843d75..059e6050 100644 --- a/src/path/mod.rs +++ b/src/path/mod.rs @@ -52,6 +52,10 @@ //! path.push("system32"); //! //! path.set_extension("dll"); +//! +//! // ... but push is best used if you don't know everything up +//! // front. If you do, this way is better: +//! let path: PathBuf = ["c:\\", "windows", "system32.dll"].iter().collect(); //! ``` //! //! [`Component`]: enum.Component.html diff --git a/src/path/pathbuf.rs b/src/path/pathbuf.rs index aae5de64..cf2e6bfe 100644 --- a/src/path/pathbuf.rs +++ b/src/path/pathbuf.rs @@ -283,3 +283,17 @@ impl<'b, P: AsRef + 'b> FromStream

for PathBuf { }) } } + +impl> std::iter::FromIterator

for PathBuf { + fn from_iter>(iter: I) -> PathBuf { + let mut buf = PathBuf::new(); + buf.extend(iter); + buf + } +} + +impl> std::iter::Extend

for PathBuf { + fn extend>(&mut self, iter: I) { + iter.into_iter().for_each(move |p| self.push(p.as_ref())); + } +}