File tree 3 files changed +466
-219
lines changed
3 files changed +466
-219
lines changed Original file line number Diff line number Diff line change @@ -148,6 +148,7 @@ use core::task::{Context, Poll};
148
148
use crate :: alloc:: { self , AllocInit , AllocRef , Global } ;
149
149
use crate :: raw_vec:: RawVec ;
150
150
use crate :: str:: from_boxed_utf8_unchecked;
151
+ use crate :: string:: String ;
151
152
use crate :: vec:: Vec ;
152
153
153
154
/// A pointer type for heap allocation.
@@ -1001,6 +1002,26 @@ impl From<&str> for Box<str> {
1001
1002
}
1002
1003
}
1003
1004
1005
+ #[ stable( feature = "box_from_str" , since = "1.20.0" ) ]
1006
+ impl < A : AllocRef > From < String < A > > for Box < str , A > {
1007
+ /// Converts the given `String` to a boxed `str` slice that is owned.
1008
+ ///
1009
+ /// # Examples
1010
+ ///
1011
+ /// Basic usage:
1012
+ ///
1013
+ /// ```
1014
+ /// let s1: String = String::from("hello world");
1015
+ /// let s2: Box<str> = Box::from(s1);
1016
+ /// let s3: String = String::from(s2);
1017
+ ///
1018
+ /// assert_eq!("hello world", s3)
1019
+ /// ```
1020
+ fn from ( s : String < A > ) -> Self {
1021
+ s. into_boxed_str ( )
1022
+ }
1023
+ }
1024
+
1004
1025
#[ stable( feature = "boxed_str_conv" , since = "1.19.0" ) ]
1005
1026
impl < A : AllocRef > From < Box < str , A > > for Box < [ u8 ] , A > {
1006
1027
/// Converts a `Box<str>>` into a `Box<[u8]>`
Original file line number Diff line number Diff line change @@ -183,15 +183,15 @@ where
183
183
}
184
184
185
185
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
186
- impl Borrow < str > for String {
186
+ impl < A : AllocRef > Borrow < str > for String < A > {
187
187
#[ inline]
188
188
fn borrow ( & self ) -> & str {
189
189
& self [ ..]
190
190
}
191
191
}
192
192
193
193
#[ stable( feature = "string_borrow_mut" , since = "1.36.0" ) ]
194
- impl BorrowMut < str > for String {
194
+ impl < A : AllocRef > BorrowMut < str > for String < A > {
195
195
#[ inline]
196
196
fn borrow_mut ( & mut self ) -> & mut str {
197
197
& mut self [ ..]
You can’t perform that action at this time.
0 commit comments