Rollup merge of #44457 - napen123:master, r=frewsxcv
Add doc examples for str::as_bytes_mut Fixes #44427
This commit is contained in:
commit
329ed4affe
1 changed files with 28 additions and 0 deletions
|
@ -297,6 +297,34 @@ impl str {
|
||||||
/// [`str::from_utf8_mut`] function.
|
/// [`str::from_utf8_mut`] function.
|
||||||
///
|
///
|
||||||
/// [`str::from_utf8_mut`]: ./str/fn.from_utf8_mut.html
|
/// [`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")]
|
#[stable(feature = "str_mut_extras", since = "1.20.0")]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn as_bytes_mut(&mut self) -> &mut [u8] {
|
pub unsafe fn as_bytes_mut(&mut self) -> &mut [u8] {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue