File tree 2 files changed +38
-0
lines changed
2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -1956,6 +1956,25 @@ where
1956
1956
}
1957
1957
}
1958
1958
1959
+ #[ stable( feature = "shared_from_str" , since = "1.61.0" ) ]
1960
+ impl From < Rc < str > > for Rc < [ u8 ] > {
1961
+ /// Converts a reference-counted string slice into a byte slice.
1962
+ ///
1963
+ /// # Example
1964
+ ///
1965
+ /// ```
1966
+ /// # use std::rc::Rc;
1967
+ /// let string: Rc<str> = Rc::from("eggplant");
1968
+ /// let bytes: Rc<[u8]> = Rc::from(string);
1969
+ /// assert_eq!("eggplant".as_bytes(), bytes.as_ref());
1970
+ /// ```
1971
+ #[ inline]
1972
+ fn from ( rc : Rc < str > ) -> Self {
1973
+ // SAFETY: `str` has the same layout as `[u8]`.
1974
+ unsafe { Rc :: from_raw ( Rc :: into_raw ( rc) as * const [ u8 ] ) }
1975
+ }
1976
+ }
1977
+
1959
1978
#[ stable( feature = "boxed_slice_try_from" , since = "1.43.0" ) ]
1960
1979
impl < T , const N : usize > TryFrom < Rc < [ T ] > > for Rc < [ T ; N ] > {
1961
1980
type Error = Rc < [ T ] > ;
Original file line number Diff line number Diff line change @@ -2556,6 +2556,25 @@ where
2556
2556
}
2557
2557
}
2558
2558
2559
+ #[ stable( feature = "shared_from_str" , since = "1.61.0" ) ]
2560
+ impl From < Arc < str > > for Arc < [ u8 ] > {
2561
+ /// Converts an atomically reference-counted string slice into a byte slice.
2562
+ ///
2563
+ /// # Example
2564
+ ///
2565
+ /// ```
2566
+ /// # use std::sync::Arc;
2567
+ /// let string: Arc<str> = Arc::from("eggplant");
2568
+ /// let bytes: Arc<[u8]> = Arc::from(string);
2569
+ /// assert_eq!("eggplant".as_bytes(), bytes.as_ref());
2570
+ /// ```
2571
+ #[ inline]
2572
+ fn from ( rc : Arc < str > ) -> Self {
2573
+ // SAFETY: `str` has the same layout as `[u8]`.
2574
+ unsafe { Arc :: from_raw ( Arc :: into_raw ( rc) as * const [ u8 ] ) }
2575
+ }
2576
+ }
2577
+
2559
2578
#[ stable( feature = "boxed_slice_try_from" , since = "1.43.0" ) ]
2560
2579
impl < T , const N : usize > TryFrom < Arc < [ T ] > > for Arc < [ T ; N ] > {
2561
2580
type Error = Arc < [ T ] > ;
You can’t perform that action at this time.
0 commit comments