File tree 3 files changed +30
-1
lines changed
3 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -677,7 +677,13 @@ impl Borrow<OsStr> for OsString {
677
677
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
678
678
impl ToOwned for OsStr {
679
679
type Owned = OsString ;
680
- fn to_owned ( & self ) -> OsString { self . to_os_string ( ) }
680
+ fn to_owned ( & self ) -> OsString {
681
+ self . to_os_string ( )
682
+ }
683
+ fn clone_into ( & self , target : & mut OsString ) {
684
+ target. clear ( ) ;
685
+ target. push ( self ) ;
686
+ }
681
687
}
682
688
683
689
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -863,4 +869,14 @@ mod tests {
863
869
let boxed = <Box < OsStr > >:: default ( ) ;
864
870
assert ! ( boxed. is_empty( ) ) ;
865
871
}
872
+
873
+ #[ test]
874
+ fn test_os_str_clone_into ( ) {
875
+ let mut os_string = OsString :: with_capacity ( 123 ) ;
876
+ os_string. push ( "hello" ) ;
877
+ let os_str = OsStr :: new ( "bonjour" ) ;
878
+ os_str. clone_into ( & mut os_string) ;
879
+ assert_eq ! ( os_str, os_string) ;
880
+ assert ! ( os_string. capacity( ) >= 123 ) ;
881
+ }
866
882
}
Original file line number Diff line number Diff line change 311
311
#![ feature( str_utf16) ]
312
312
#![ feature( test, rustc_private) ]
313
313
#![ feature( thread_local) ]
314
+ #![ feature( toowned_clone_into) ]
314
315
#![ feature( try_from) ]
315
316
#![ feature( unboxed_closures) ]
316
317
#![ feature( unicode) ]
Original file line number Diff line number Diff line change @@ -1414,6 +1414,9 @@ impl ToOwned for Path {
1414
1414
fn to_owned ( & self ) -> PathBuf {
1415
1415
self . to_path_buf ( )
1416
1416
}
1417
+ fn clone_into ( & self , target : & mut PathBuf ) {
1418
+ self . inner . clone_into ( & mut target. inner ) ;
1419
+ }
1417
1420
}
1418
1421
1419
1422
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -3859,4 +3862,13 @@ mod tests {
3859
3862
assert_eq ! ( & * boxed, & * path_buf) ;
3860
3863
assert_eq ! ( & * path_buf, path) ;
3861
3864
}
3865
+
3866
+ #[ test]
3867
+ fn test_clone_into ( ) {
3868
+ let mut path_buf = PathBuf :: from ( "supercalifragilisticexpialidocious" ) ;
3869
+ let path = Path :: new ( "short" ) ;
3870
+ path. clone_into ( & mut path_buf) ;
3871
+ assert_eq ! ( path, path_buf) ;
3872
+ assert ! ( path_buf. into_os_string( ) . capacity( ) >= 15 ) ;
3873
+ }
3862
3874
}
You can’t perform that action at this time.
0 commit comments