@@ -206,7 +206,7 @@ impl OsString {
206206 }
207207
208208 /// Converts this `OsString` into a boxed `OsStr`.
209- #[ unstable( feature = "into_boxed_os_str" , issue = "0 " ) ]
209+ #[ unstable( feature = "into_boxed_os_str" , issue = "40380 " ) ]
210210 pub fn into_boxed_os_str ( self ) -> Box < OsStr > {
211211 unsafe { mem:: transmute ( self . inner . into_box ( ) ) }
212212 }
@@ -442,6 +442,13 @@ impl OsStr {
442442 self . inner . inner . len ( )
443443 }
444444
445+ /// Converts a `Box<OsStr>` into an `OsString` without copying or allocating.
446+ #[ unstable( feature = "into_boxed_os_str" , issue = "40380" ) ]
447+ pub fn into_os_string ( self : Box < OsStr > ) -> OsString {
448+ let inner: Box < Slice > = unsafe { mem:: transmute ( self ) } ;
449+ OsString { inner : Buf :: from_box ( inner) }
450+ }
451+
445452 /// Gets the underlying byte representation.
446453 ///
447454 /// Note: it is *crucial* that this API is private, to avoid
@@ -458,6 +465,20 @@ impl<'a> From<&'a OsStr> for Box<OsStr> {
458465 }
459466}
460467
468+ #[ stable( feature = "os_string_from_box" , since = "1.17.0" ) ]
469+ impl < ' a > From < Box < OsStr > > for OsString {
470+ fn from ( boxed : Box < OsStr > ) -> OsString {
471+ boxed. into_os_string ( )
472+ }
473+ }
474+
475+ #[ stable( feature = "box_from_c_string" , since = "1.17.0" ) ]
476+ impl Into < Box < OsStr > > for OsString {
477+ fn into ( self ) -> Box < OsStr > {
478+ self . into_boxed_os_str ( )
479+ }
480+ }
481+
461482#[ stable( feature = "box_default_extra" , since = "1.17.0" ) ]
462483impl Default for Box < OsStr > {
463484 fn default ( ) -> Box < OsStr > {
@@ -766,12 +787,11 @@ mod tests {
766787 fn into_boxed ( ) {
767788 let orig = "Hello, world!" ;
768789 let os_str = OsStr :: new ( orig) ;
769- let os_string = os_str. to_owned ( ) ;
770- let box1: Box < OsStr > = Box :: from ( os_str) ;
771- let box2 = os_string. into_boxed_os_str ( ) ;
772- assert_eq ! ( os_str, & * box1) ;
773- assert_eq ! ( box1, box2) ;
774- assert_eq ! ( & * box2, os_str) ;
790+ let boxed: Box < OsStr > = Box :: from ( os_str) ;
791+ let os_string = os_str. to_owned ( ) . into_boxed_os_str ( ) . into_os_string ( ) ;
792+ assert_eq ! ( os_str, & * boxed) ;
793+ assert_eq ! ( & * boxed, & * os_string) ;
794+ assert_eq ! ( & * os_string, os_str) ;
775795 }
776796
777797 #[ test]
0 commit comments