Add FromIterator and Extend trait implementations for PathBuf

pull/483/head
Ryan Scott 5 years ago
parent fb19ebde17
commit 8f3366072f

@ -52,6 +52,10 @@
//! path.push("system32"); //! path.push("system32");
//! //!
//! path.set_extension("dll"); //! 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 //! [`Component`]: enum.Component.html

@ -280,3 +280,17 @@ impl<'b, P: AsRef<Path> + 'b> FromStream<P> for PathBuf {
}) })
} }
} }
impl<P: AsRef<Path>> std::iter::FromIterator<P> for PathBuf {
fn from_iter<I: IntoIterator<Item = P>>(iter: I) -> PathBuf {
let mut buf = PathBuf::new();
buf.extend(iter);
buf
}
}
impl<P: AsRef<Path>> std::iter::Extend<P> for PathBuf {
fn extend<I: IntoIterator<Item = P>>(&mut self, iter: I) {
iter.into_iter().for_each(move |p| self.push(p.as_ref()));
}
}

Loading…
Cancel
Save