Skip to content

Commit

Permalink
Rollup merge of rust-lang#74381 - mbrubeck:docs, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
Update docs for str::as_bytes_mut.

* Add "Safety" section describing UTF-8 invariant.

* Remove mention of `from_utf8_mut`.  It is not necessary to call
  a function to convert the byte slice back to a string slice.  The
  original string becomes accessible again after the byte slice is
  no longer used (as shown in the example code).
  • Loading branch information
Manishearth authored Jul 16, 2020
2 parents 7910b5c + 6da69ec commit 7c7b649
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2374,11 +2374,14 @@ impl str {
unsafe { Slices { str: self }.slice }
}

/// Converts a mutable string slice to a mutable byte slice. To convert the
/// mutable byte slice back into a mutable string slice, use the
/// [`str::from_utf8_mut`] function.
/// Converts a mutable string slice to a mutable byte slice.
///
/// [`str::from_utf8_mut`]: ./str/fn.from_utf8_mut.html
/// # Safety
///
/// The caller must ensure that the content of the slice is valid UTF-8
/// before the borrow ends and the underlying `str` is used.
///
/// Use of a `str` whose contents are not valid UTF-8 is undefined behavior.
///
/// # Examples
///
Expand Down

0 comments on commit 7c7b649

Please sign in to comment.