File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -297,6 +297,34 @@ impl str {
297297 /// [`str::from_utf8_mut`] function.
298298 ///
299299 /// [`str::from_utf8_mut`]: ./str/fn.from_utf8_mut.html
300+ ///
301+ /// # Examples
302+ ///
303+ /// Basic usage:
304+ ///
305+ /// ```
306+ /// let mut s = String::from("Hello");
307+ /// let bytes = unsafe { s.as_bytes_mut() };
308+ ///
309+ /// assert_eq!(b"Hello", bytes);
310+ /// ```
311+ ///
312+ /// Mutability:
313+ ///
314+ /// ```
315+ /// let mut s = String::from("π»βπ");
316+ ///
317+ /// unsafe {
318+ /// let bytes = s.as_bytes_mut();
319+ ///
320+ /// bytes[0] = 0xF0;
321+ /// bytes[1] = 0x9F;
322+ /// bytes[2] = 0x8D;
323+ /// bytes[3] = 0x94;
324+ /// }
325+ ///
326+ /// assert_eq!("πβπ", s);
327+ /// ```
300328 #[ stable( feature = "str_mut_extras" , since = "1.20.0" ) ]
301329 #[ inline( always) ]
302330 pub unsafe fn as_bytes_mut ( & mut self ) -> & mut [ u8 ] {
You canβt perform that action at this time.
0 commit comments