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:
parent
fb19ebde17
commit
8f3366072f
2 changed files with 18 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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…
Reference in a new issue