@@ -61,6 +61,7 @@ use core::result::Result;
61
61
use core:: str as core_str;
62
62
use core:: str:: pattern:: Pattern ;
63
63
use core:: str:: pattern:: { Searcher , ReverseSearcher , DoubleEndedSearcher } ;
64
+ use core:: mem;
64
65
use rustc_unicode:: str:: { UnicodeStr , Utf16Encoder } ;
65
66
66
67
use vec_deque:: VecDeque ;
@@ -69,6 +70,7 @@ use string::String;
69
70
use rustc_unicode;
70
71
use vec:: Vec ;
71
72
use slice:: SliceConcatExt ;
73
+ use boxed:: Box ;
72
74
73
75
pub use core:: str:: { FromStr , Utf8Error } ;
74
76
pub use core:: str:: { Lines , LinesAny , CharRange } ;
@@ -82,10 +84,6 @@ pub use core::str::{from_utf8_unchecked, ParseBoolError};
82
84
pub use rustc_unicode:: str:: { SplitWhitespace , Words , Graphemes , GraphemeIndices } ;
83
85
pub use core:: str:: pattern;
84
86
85
- /*
86
- Section: Creating a string
87
- */
88
-
89
87
impl < S : Borrow < str > > SliceConcatExt < str > for [ S ] {
90
88
type Output = String ;
91
89
@@ -134,10 +132,6 @@ impl<S: Borrow<str>> SliceConcatExt<str> for [S] {
134
132
}
135
133
}
136
134
137
- /*
138
- Section: Iterators
139
- */
140
-
141
135
// Helper functions used for Unicode normalization
142
136
fn canonical_sort ( comb : & mut [ ( char , u8 ) ] ) {
143
137
let len = comb. len ( ) ;
@@ -382,10 +376,6 @@ impl<'a> Iterator for Utf16Units<'a> {
382
376
fn size_hint ( & self ) -> ( usize , Option < usize > ) { self . encoder . size_hint ( ) }
383
377
}
384
378
385
- /*
386
- Section: Misc
387
- */
388
-
389
379
// Return the initial codepoint accumulator for the first byte.
390
380
// The first byte is special, only want bottom 5 bits for width 2, 4 bits
391
381
// for width 3, and 3 bits for width 4
@@ -414,15 +404,6 @@ impl ToOwned for str {
414
404
}
415
405
}
416
406
417
- /*
418
- Section: CowString
419
- */
420
-
421
- /*
422
- Section: Trait implementations
423
- */
424
-
425
-
426
407
/// Any string that can be represented as a slice.
427
408
#[ lang = "str" ]
428
409
#[ cfg( not( test) ) ]
@@ -1924,4 +1905,14 @@ impl str {
1924
1905
pub fn escape_unicode ( & self ) -> String {
1925
1906
self . chars ( ) . flat_map ( |c| c. escape_unicode ( ) ) . collect ( )
1926
1907
}
1908
+
1909
+ /// Converts the `Box<str>` into a `String` without copying or allocating.
1910
+ #[ unstable( feature = "box_str" ,
1911
+ reason = "recently added, matches RFC" ) ]
1912
+ pub fn into_string ( self : Box < str > ) -> String {
1913
+ unsafe {
1914
+ let slice = mem:: transmute :: < Box < str > , Box < [ u8 ] > > ( self ) ;
1915
+ String :: from_utf8_unchecked ( slice. into_vec ( ) )
1916
+ }
1917
+ }
1927
1918
}
0 commit comments