Skip to content

Commit

Permalink
Rollup merge of rust-lang#44457 - napen123:master, r=frewsxcv
Browse files Browse the repository at this point in the history
Add doc examples for str::as_bytes_mut

Fixes rust-lang#44427
  • Loading branch information
GuillaumeGomez authored Sep 10, 2017
2 parents 485847d + 6c89935 commit 329ed4a
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/liballoc/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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] {
Expand Down

0 comments on commit 329ed4a

Please sign in to comment.