@@ -13,6 +13,8 @@ use fmt;
1313use ops;
1414use cmp;
1515use hash:: { Hash , Hasher } ;
16+ use rc:: Rc ;
17+ use sync:: Arc ;
1618
1719use sys:: os_str:: { Buf , Slice } ;
1820use sys_common:: { AsInner , IntoInner , FromInner } ;
@@ -592,6 +594,42 @@ impl From<OsString> for Box<OsStr> {
592594 }
593595}
594596
597+ #[ stable( feature = "shared_from_slice2" , since = "1.23.0" ) ]
598+ impl From < OsString > for Arc < OsStr > {
599+ #[ inline]
600+ fn from ( s : OsString ) -> Arc < OsStr > {
601+ let arc = s. inner . into_arc ( ) ;
602+ unsafe { Arc :: from_raw ( Arc :: into_raw ( arc) as * const OsStr ) }
603+ }
604+ }
605+
606+ #[ stable( feature = "shared_from_slice2" , since = "1.23.0" ) ]
607+ impl < ' a > From < & ' a OsStr > for Arc < OsStr > {
608+ #[ inline]
609+ fn from ( s : & OsStr ) -> Arc < OsStr > {
610+ let arc = s. inner . into_arc ( ) ;
611+ unsafe { Arc :: from_raw ( Arc :: into_raw ( arc) as * const OsStr ) }
612+ }
613+ }
614+
615+ #[ stable( feature = "shared_from_slice2" , since = "1.23.0" ) ]
616+ impl From < OsString > for Rc < OsStr > {
617+ #[ inline]
618+ fn from ( s : OsString ) -> Rc < OsStr > {
619+ let rc = s. inner . into_rc ( ) ;
620+ unsafe { Rc :: from_raw ( Rc :: into_raw ( rc) as * const OsStr ) }
621+ }
622+ }
623+
624+ #[ stable( feature = "shared_from_slice2" , since = "1.23.0" ) ]
625+ impl < ' a > From < & ' a OsStr > for Rc < OsStr > {
626+ #[ inline]
627+ fn from ( s : & OsStr ) -> Rc < OsStr > {
628+ let rc = s. inner . into_rc ( ) ;
629+ unsafe { Rc :: from_raw ( Rc :: into_raw ( rc) as * const OsStr ) }
630+ }
631+ }
632+
595633#[ stable( feature = "box_default_extra" , since = "1.17.0" ) ]
596634impl Default for Box < OsStr > {
597635 fn default ( ) -> Box < OsStr > {
@@ -793,6 +831,9 @@ mod tests {
793831 use super :: * ;
794832 use sys_common:: { AsInner , IntoInner } ;
795833
834+ use rc:: Rc ;
835+ use sync:: Arc ;
836+
796837 #[ test]
797838 fn test_os_string_with_capacity ( ) {
798839 let os_string = OsString :: with_capacity ( 0 ) ;
@@ -935,4 +976,21 @@ mod tests {
935976 assert_eq ! ( os_str, os_string) ;
936977 assert ! ( os_string. capacity( ) >= 123 ) ;
937978 }
979+
980+ #[ test]
981+ fn into_rc ( ) {
982+ let orig = "Hello, world!" ;
983+ let os_str = OsStr :: new ( orig) ;
984+ let rc: Rc < OsStr > = Rc :: from ( os_str) ;
985+ let arc: Arc < OsStr > = Arc :: from ( os_str) ;
986+
987+ assert_eq ! ( & * rc, os_str) ;
988+ assert_eq ! ( & * arc, os_str) ;
989+
990+ let rc2: Rc < OsStr > = Rc :: from ( os_str. to_owned ( ) ) ;
991+ let arc2: Arc < OsStr > = Arc :: from ( os_str. to_owned ( ) ) ;
992+
993+ assert_eq ! ( & * rc2, os_str) ;
994+ assert_eq ! ( & * arc2, os_str) ;
995+ }
938996}
0 commit comments