File tree Expand file tree Collapse file tree 6 files changed +17
-48
lines changed Expand file tree Collapse file tree 6 files changed +17
-48
lines changed Original file line number Diff line number Diff line change 147147#![ feature( slice_ptr_get) ]
148148#![ feature( slice_range) ]
149149#![ feature( std_internals) ]
150+ #![ feature( str_as_str) ]
150151#![ feature( str_internals) ]
151152#![ feature( strict_provenance) ]
152153#![ feature( trusted_fused) ]
Original file line number Diff line number Diff line change @@ -448,7 +448,11 @@ fn test_from_box_str() {
448448 use std:: string:: String ;
449449
450450 let s = String :: from ( "foo" ) . into_boxed_str ( ) ;
451+ assert_eq ! ( ( &&& s) . as_str( ) , "foo" ) ;
452+
451453 let r: Rc < str > = Rc :: from ( s) ;
454+ assert_eq ! ( ( & r) . as_str( ) , "foo" ) ;
455+ assert_eq ! ( r. as_str( ) , "foo" ) ;
452456
453457 assert_eq ! ( & r[ ..] , "foo" ) ;
454458}
Original file line number Diff line number Diff line change @@ -2736,6 +2736,17 @@ impl str {
27362736 pub fn substr_range ( & self , substr : & str ) -> Option < Range < usize > > {
27372737 self . as_bytes ( ) . subslice_range ( substr. as_bytes ( ) )
27382738 }
2739+
2740+ /// Returns the same string as a string slice `&str`.
2741+ ///
2742+ /// This method is redundant when used directly on `&str`, but
2743+ /// it helps dereferencing other string-like types to string slices,
2744+ /// for example references to `Box<str>` or `Arc<str>`.
2745+ #[ inline]
2746+ #[ unstable( feature = "str_as_str" , issue = "130366" ) ]
2747+ pub fn as_str ( & self ) -> & str {
2748+ self
2749+ }
27392750}
27402751
27412752#[ stable( feature = "rust1" , since = "1.0.0" ) ]
Original file line number Diff line number Diff line change 351351#![ feature( slice_ptr_get) ]
352352#![ feature( slice_range) ]
353353#![ feature( std_internals) ]
354+ #![ feature( str_as_str) ]
354355#![ feature( str_internals) ]
355356#![ feature( strict_provenance) ]
356357#![ feature( strict_provenance_atomic_ptr) ]
Load Diff This file was deleted.
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments