Skip to content

Commit a77813b

Browse files
authored
Rollup merge of rust-lang#74381 - mbrubeck:docs, r=Mark-Simulacrum
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).
2 parents 4b4ea68 + 6da69ec commit a77813b

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/libcore/str/mod.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -2374,11 +2374,14 @@ impl str {
23742374
unsafe { Slices { str: self }.slice }
23752375
}
23762376

2377-
/// Converts a mutable string slice to a mutable byte slice. To convert the
2378-
/// mutable byte slice back into a mutable string slice, use the
2379-
/// [`str::from_utf8_mut`] function.
2377+
/// Converts a mutable string slice to a mutable byte slice.
23802378
///
2381-
/// [`str::from_utf8_mut`]: ./str/fn.from_utf8_mut.html
2379+
/// # Safety
2380+
///
2381+
/// The caller must ensure that the content of the slice is valid UTF-8
2382+
/// before the borrow ends and the underlying `str` is used.
2383+
///
2384+
/// Use of a `str` whose contents are not valid UTF-8 is undefined behavior.
23822385
///
23832386
/// # Examples
23842387
///

0 commit comments

Comments
 (0)