2
0
Fork 1
mirror of https://github.com/async-rs/async-std.git synced 2025-02-28 23:29:41 +00:00

Add FromIterator and Extend trait implementations for PathBuf

This commit is contained in:
Ryan Scott 2019-11-08 22:08:53 +11:00
parent fb19ebde17
commit 8f3366072f
2 changed files with 18 additions and 0 deletions

View file

@ -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

View file

@ -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()));
}
}