File tree 1 file changed +34
-0
lines changed
1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -1204,6 +1204,16 @@ impl<'a> Extend<&'a OsStr> for OsString {
1204
1204
}
1205
1205
}
1206
1206
1207
+ #[ stable( feature = "osstring_extend" , since = "1.52.0" ) ]
1208
+ impl < ' a > Extend < Cow < ' a , OsStr > > for OsString {
1209
+ #[ inline]
1210
+ fn extend < T : IntoIterator < Item = Cow < ' a , OsStr > > > ( & mut self , iter : T ) {
1211
+ for s in iter {
1212
+ self . push ( & s) ;
1213
+ }
1214
+ }
1215
+ }
1216
+
1207
1217
#[ stable( feature = "osstring_extend" , since = "1.52.0" ) ]
1208
1218
impl FromIterator < OsString > for OsString {
1209
1219
#[ inline]
@@ -1234,3 +1244,27 @@ impl<'a> FromIterator<&'a OsStr> for OsString {
1234
1244
buf
1235
1245
}
1236
1246
}
1247
+
1248
+ #[ stable( feature = "osstring_extend" , since = "1.52.0" ) ]
1249
+ impl < ' a > FromIterator < Cow < ' a , OsStr > > for OsString {
1250
+ #[ inline]
1251
+ fn from_iter < I : IntoIterator < Item = Cow < ' a , OsStr > > > ( iter : I ) -> Self {
1252
+ let mut iterator = iter. into_iter ( ) ;
1253
+
1254
+ // Because we're iterating over `OsString`s, we can avoid at least
1255
+ // one allocation by getting the first owned string from the iterator
1256
+ // and appending to it all the subsequent strings.
1257
+ match iterator. next ( ) {
1258
+ None => OsString :: new ( ) ,
1259
+ Some ( Cow :: Owned ( mut buf) ) => {
1260
+ buf. extend ( iterator) ;
1261
+ buf
1262
+ }
1263
+ Some ( Cow :: Borrowed ( buf) ) => {
1264
+ let mut buf = OsString :: from ( buf) ;
1265
+ buf. extend ( iterator) ;
1266
+ buf
1267
+ }
1268
+ }
1269
+ }
1270
+ }
You can’t perform that action at this time.
0 commit comments