File tree 4 files changed +17
-0
lines changed
4 files changed +17
-0
lines changed Original file line number Diff line number Diff line change 147
147
#![ feature( slice_ptr_get) ]
148
148
#![ feature( slice_range) ]
149
149
#![ feature( std_internals) ]
150
+ #![ feature( str_as_str) ]
150
151
#![ feature( str_internals) ]
151
152
#![ feature( strict_provenance) ]
152
153
#![ feature( trusted_fused) ]
Original file line number Diff line number Diff line change @@ -448,7 +448,11 @@ fn test_from_box_str() {
448
448
use std:: string:: String ;
449
449
450
450
let s = String :: from ( "foo" ) . into_boxed_str ( ) ;
451
+ assert_eq ! ( ( &&& s) . as_str( ) , "foo" ) ;
452
+
451
453
let r: Rc < str > = Rc :: from ( s) ;
454
+ assert_eq ! ( ( & r) . as_str( ) , "foo" ) ;
455
+ assert_eq ! ( r. as_str( ) , "foo" ) ;
452
456
453
457
assert_eq ! ( & r[ ..] , "foo" ) ;
454
458
}
Original file line number Diff line number Diff line change @@ -2736,6 +2736,17 @@ impl str {
2736
2736
pub fn substr_range ( & self , substr : & str ) -> Option < Range < usize > > {
2737
2737
self . as_bytes ( ) . subslice_range ( substr. as_bytes ( ) )
2738
2738
}
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
+ }
2739
2750
}
2740
2751
2741
2752
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
Original file line number Diff line number Diff line change 351
351
#![ feature( slice_ptr_get) ]
352
352
#![ feature( slice_range) ]
353
353
#![ feature( std_internals) ]
354
+ #![ feature( str_as_str) ]
354
355
#![ feature( str_internals) ]
355
356
#![ feature( strict_provenance) ]
356
357
#![ feature( strict_provenance_atomic_ptr) ]
You can’t perform that action at this time.
0 commit comments