File tree Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -1222,6 +1222,23 @@ impl OsStr {
12221222 }
12231223}
12241224
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) = slice. first ( ) else {
1231+ return OsString :: new ( ) ;
1232+ } ;
1233+ let first = first. borrow ( ) . to_owned ( ) ;
1234+ slice[ 1 ..] . iter ( ) . fold ( first, |mut a, b| {
1235+ a. push ( sep) ;
1236+ a. push ( b. borrow ( ) ) ;
1237+ a
1238+ } )
1239+ }
1240+ }
1241+
12251242#[ stable( feature = "rust1" , since = "1.0.0" ) ]
12261243impl Borrow < OsStr > for OsString {
12271244 #[ inline]
Original file line number Diff line number Diff line change @@ -84,6 +84,20 @@ fn test_os_string_reserve_exact() {
8484 assert ! ( os_string. capacity( ) >= 33 )
8585}
8686
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+
87101#[ test]
88102fn test_os_string_default ( ) {
89103 let os_string: OsString = Default :: default ( ) ;
Original file line number Diff line number Diff line change 241241#![ feature( intra_doc_pointers) ]
242242#![ feature( lang_items) ]
243243#![ feature( let_chains) ]
244+ #![ feature( let_else) ]
244245#![ feature( linkage) ]
245246#![ feature( min_specialization) ]
246247#![ feature( must_not_suspend) ]
300301#![ feature( toowned_clone_into) ]
301302#![ feature( try_reserve_kind) ]
302303#![ feature( vec_into_raw_parts) ]
304+ #![ feature( slice_concat_trait) ]
303305//
304306// Library features (unwind):
305307#![ feature( panic_unwind) ]
You can’t perform that action at this time.
0 commit comments