@@ -1757,7 +1757,7 @@ mod traits {
1757
1757
}
1758
1758
#[ inline]
1759
1759
unsafe fn get_unchecked_mut ( self , slice : & mut str ) -> & mut Self :: Output {
1760
- let ptr = slice. as_ptr ( ) . add ( self . start ) ;
1760
+ let ptr = slice. as_mut_ptr ( ) . add ( self . start ) ;
1761
1761
let len = self . end - self . start ;
1762
1762
super :: from_utf8_unchecked_mut ( slice:: from_raw_parts_mut ( ptr as * mut u8 , len) )
1763
1763
}
@@ -1821,7 +1821,7 @@ mod traits {
1821
1821
}
1822
1822
#[ inline]
1823
1823
unsafe fn get_unchecked_mut ( self , slice : & mut str ) -> & mut Self :: Output {
1824
- let ptr = slice. as_ptr ( ) ;
1824
+ let ptr = slice. as_mut_ptr ( ) ;
1825
1825
super :: from_utf8_unchecked_mut ( slice:: from_raw_parts_mut ( ptr as * mut u8 , self . end ) )
1826
1826
}
1827
1827
#[ inline]
@@ -1883,7 +1883,7 @@ mod traits {
1883
1883
}
1884
1884
#[ inline]
1885
1885
unsafe fn get_unchecked_mut ( self , slice : & mut str ) -> & mut Self :: Output {
1886
- let ptr = slice. as_ptr ( ) . add ( self . start ) ;
1886
+ let ptr = slice. as_mut_ptr ( ) . add ( self . start ) ;
1887
1887
let len = slice. len ( ) - self . start ;
1888
1888
super :: from_utf8_unchecked_mut ( slice:: from_raw_parts_mut ( ptr as * mut u8 , len) )
1889
1889
}
@@ -2213,6 +2213,22 @@ impl str {
2213
2213
self as * const str as * const u8
2214
2214
}
2215
2215
2216
+ /// Converts a mutable string slice to a raw pointer.
2217
+ ///
2218
+ /// As string slices are a slice of bytes, the raw pointer points to a
2219
+ /// [`u8`]. This pointer will be pointing to the first byte of the string
2220
+ /// slice.
2221
+ ///
2222
+ /// It is your responsibility to make sure that the string slice only gets
2223
+ /// modified in a way that it remains valid UTF-8.
2224
+ ///
2225
+ /// [`u8`]: primitive.u8.html
2226
+ #[ unstable( feature = "str_as_mut_ptr" , issue = "0" ) ]
2227
+ #[ inline]
2228
+ pub fn as_mut_ptr ( & mut self ) -> * mut u8 {
2229
+ self as * mut str as * mut u8
2230
+ }
2231
+
2216
2232
/// Returns a subslice of `str`.
2217
2233
///
2218
2234
/// This is the non-panicking alternative to indexing the `str`. Returns
0 commit comments