mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-26 14:43:24 +00:00
Implement Extend and FromIterator for OsString
Add the following trait impls: - `impl Extend<OsString> for OsString` - `impl<'a> Extend<&'a OsStr> for OsString` - `impl FromIterator<OsString> for OsString` - `impl<'a> FromIterator<&'a OsStr> for OsString` Because `OsString` is a platform string with no particular semantics, concatenating them together seems acceptable.
This commit is contained in:
parent
5fa22fe6f8
commit
3ed6184434
@ -5,6 +5,7 @@ use crate::borrow::{Borrow, Cow};
|
||||
use crate::cmp;
|
||||
use crate::fmt;
|
||||
use crate::hash::{Hash, Hasher};
|
||||
use crate::iter::{Extend, FromIterator};
|
||||
use crate::ops;
|
||||
use crate::rc::Rc;
|
||||
use crate::str::FromStr;
|
||||
@ -1182,3 +1183,47 @@ impl FromStr for OsString {
|
||||
Ok(OsString::from(s))
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "osstring_extend", since = "1.52.0")]
|
||||
impl Extend<OsString> for OsString {
|
||||
#[inline]
|
||||
fn extend<T: IntoIterator<Item = OsString>>(&mut self, iter: T) {
|
||||
for s in iter {
|
||||
self.push(&s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "osstring_extend", since = "1.52.0")]
|
||||
impl<'a> Extend<&'a OsStr> for OsString {
|
||||
#[inline]
|
||||
fn extend<T: IntoIterator<Item = &'a OsStr>>(&mut self, iter: T) {
|
||||
for s in iter {
|
||||
self.push(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "osstring_extend", since = "1.52.0")]
|
||||
impl FromIterator<OsString> for OsString {
|
||||
#[inline]
|
||||
fn from_iter<I: IntoIterator<Item = OsString>>(iter: I) -> Self {
|
||||
let mut buf = Self::new();
|
||||
for s in iter {
|
||||
buf.push(&s);
|
||||
}
|
||||
buf
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "osstring_extend", since = "1.52.0")]
|
||||
impl<'a> FromIterator<&'a OsStr> for OsString {
|
||||
#[inline]
|
||||
fn from_iter<I: IntoIterator<Item = &'a OsStr>>(iter: I) -> Self {
|
||||
let mut buf = Self::new();
|
||||
for s in iter {
|
||||
buf.push(s);
|
||||
}
|
||||
buf
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user