File tree 3 files changed +33
-0
lines changed
3 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -1222,6 +1222,23 @@ impl OsStr {
1222
1222
}
1223
1223
}
1224
1224
1225
+ #[ unstable( feature = "slice_concat_ext" , issue = "27747" ) ]
1226
+ impl < S : Borrow < OsStr > > alloc:: slice:: Join < & OsStr > for [ S ] {
1227
+ type Output = OsString ;
1228
+
1229
+ fn join ( slice : & Self , sep : & OsStr ) -> OsString {
1230
+ let Some ( ( first, suffix) ) = slice. split_first ( ) else {
1231
+ return OsString :: new ( ) ;
1232
+ } ;
1233
+ let first_owned = first. borrow ( ) . to_owned ( ) ;
1234
+ suffix. iter ( ) . fold ( first_owned, |mut a, b| {
1235
+ a. push ( sep) ;
1236
+ a. push ( b. borrow ( ) ) ;
1237
+ a
1238
+ } )
1239
+ }
1240
+ }
1241
+
1225
1242
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1226
1243
impl Borrow < OsStr > for OsString {
1227
1244
#[ inline]
Original file line number Diff line number Diff line change @@ -84,6 +84,20 @@ fn test_os_string_reserve_exact() {
84
84
assert ! ( os_string. capacity( ) >= 33 )
85
85
}
86
86
87
+ #[ test]
88
+ fn test_os_string_join ( ) {
89
+ let strings = [ OsStr :: new ( "hello" ) , OsStr :: new ( "dear" ) , OsStr :: new ( "world" ) ] ;
90
+ assert_eq ! ( "hello" , strings[ ..1 ] . join( OsStr :: new( " " ) ) ) ;
91
+ assert_eq ! ( "hello dear world" , strings. join( OsStr :: new( " " ) ) ) ;
92
+ assert_eq ! ( "hellodearworld" , strings. join( OsStr :: new( "" ) ) ) ;
93
+ assert_eq ! ( "hello.\n dear.\n world" , strings. join( OsStr :: new( ".\n " ) ) ) ;
94
+
95
+ assert_eq ! ( "dear world" , strings[ 1 ..] . join( & OsString :: from( " " ) ) ) ;
96
+
97
+ let strings_abc = [ OsString :: from ( "a" ) , OsString :: from ( "b" ) , OsString :: from ( "c" ) ] ;
98
+ assert_eq ! ( "a b c" , strings_abc. join( OsStr :: new( " " ) ) ) ;
99
+ }
100
+
87
101
#[ test]
88
102
fn test_os_string_default ( ) {
89
103
let os_string: OsString = Default :: default ( ) ;
Original file line number Diff line number Diff line change 241
241
#![ feature( intra_doc_pointers) ]
242
242
#![ feature( lang_items) ]
243
243
#![ feature( let_chains) ]
244
+ #![ feature( let_else) ]
244
245
#![ feature( linkage) ]
245
246
#![ feature( min_specialization) ]
246
247
#![ feature( must_not_suspend) ]
301
302
#![ feature( toowned_clone_into) ]
302
303
#![ feature( try_reserve_kind) ]
303
304
#![ feature( vec_into_raw_parts) ]
305
+ #![ feature( slice_concat_trait) ]
304
306
//
305
307
// Library features (unwind):
306
308
#![ feature( panic_unwind) ]
You can’t perform that action at this time.
0 commit comments