@@ -61,6 +61,7 @@ use core::result::Result;
6161use core:: str as core_str;
6262use core:: str:: pattern:: Pattern ;
6363use core:: str:: pattern:: { Searcher , ReverseSearcher , DoubleEndedSearcher } ;
64+ use core:: mem;
6465use rustc_unicode:: str:: { UnicodeStr , Utf16Encoder } ;
6566
6667use vec_deque:: VecDeque ;
@@ -69,6 +70,7 @@ use string::String;
6970use rustc_unicode;
7071use vec:: Vec ;
7172use slice:: SliceConcatExt ;
73+ use boxed:: Box ;
7274
7375pub use core:: str:: { FromStr , Utf8Error } ;
7476pub use core:: str:: { Lines , LinesAny , CharRange } ;
@@ -82,10 +84,6 @@ pub use core::str::{from_utf8_unchecked, ParseBoolError};
8284pub use rustc_unicode:: str:: { SplitWhitespace , Words , Graphemes , GraphemeIndices } ;
8385pub use core:: str:: pattern;
8486
85- /*
86- Section: Creating a string
87- */
88-
8987impl < S : Borrow < str > > SliceConcatExt < str > for [ S ] {
9088 type Output = String ;
9189
@@ -134,10 +132,6 @@ impl<S: Borrow<str>> SliceConcatExt<str> for [S] {
134132 }
135133}
136134
137- /*
138- Section: Iterators
139- */
140-
141135// Helper functions used for Unicode normalization
142136fn canonical_sort ( comb : & mut [ ( char , u8 ) ] ) {
143137 let len = comb. len ( ) ;
@@ -382,10 +376,6 @@ impl<'a> Iterator for Utf16Units<'a> {
382376 fn size_hint ( & self ) -> ( usize , Option < usize > ) { self . encoder . size_hint ( ) }
383377}
384378
385- /*
386- Section: Misc
387- */
388-
389379// Return the initial codepoint accumulator for the first byte.
390380// The first byte is special, only want bottom 5 bits for width 2, 4 bits
391381// for width 3, and 3 bits for width 4
@@ -414,15 +404,6 @@ impl ToOwned for str {
414404 }
415405}
416406
417- /*
418- Section: CowString
419- */
420-
421- /*
422- Section: Trait implementations
423- */
424-
425-
426407/// Any string that can be represented as a slice.
427408#[ lang = "str" ]
428409#[ cfg( not( test) ) ]
@@ -1924,4 +1905,14 @@ impl str {
19241905 pub fn escape_unicode ( & self ) -> String {
19251906 self . chars ( ) . flat_map ( |c| c. escape_unicode ( ) ) . collect ( )
19261907 }
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+ }
19271918}
0 commit comments