parent
18366f4e8a
commit
6c8993532c
@ -297,6 +297,34 @@ impl str {
|
||||
/// [`str::from_utf8_mut`] function.
|
||||
///
|
||||
/// [`str::from_utf8_mut`]: ./str/fn.from_utf8_mut.html
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Basic usage:
|
||||
///
|
||||
/// ```
|
||||
/// let mut s = String::from("Hello");
|
||||
/// let bytes = unsafe { s.as_bytes_mut() };
|
||||
///
|
||||
/// assert_eq!(b"Hello", bytes);
|
||||
/// ```
|
||||
///
|
||||
/// Mutability:
|
||||
///
|
||||
/// ```
|
||||
/// let mut s = String::from("🗻∈🌏");
|
||||
///
|
||||
/// unsafe {
|
||||
/// let bytes = s.as_bytes_mut();
|
||||
///
|
||||
/// bytes[0] = 0xF0;
|
||||
/// bytes[1] = 0x9F;
|
||||
/// bytes[2] = 0x8D;
|
||||
/// bytes[3] = 0x94;
|
||||
/// }
|
||||
///
|
||||
/// assert_eq!("🍔∈🌏", s);
|
||||
/// ```
|
||||
#[stable(feature = "str_mut_extras", since = "1.20.0")]
|
||||
#[inline(always)]
|
||||
pub unsafe fn as_bytes_mut(&mut self) -> &mut [u8] {
|
||||
|
Loading…
Reference in New Issue
Block a user