Merge pull request #483 from ryan-scott-dev/rscott/pathbuf_fromiter

Add FromIterator and Extend trait implementations for PathBuf
poc-serde-support
Yoshua Wuyts 5 years ago committed by GitHub
commit 89d611628a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

@ -283,3 +283,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