Skip to content

Commit

Permalink
Update string.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhoo authored May 18, 2024
1 parent 9c56d0c commit 22fc094
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions library/alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1941,6 +1941,7 @@ impl String {
/// Converts this `String` into a <code>[Box]<[str]></code>.
///
/// Before doing the conversion, this method discards excess capacity like [`shrink_to_fit`].
/// Note that the [`shrink_to_fit`] call may reallocate and copy the bytes of the string.
///
/// [`shrink_to_fit`]: String::shrink_to_fit
/// [str]: prim@str "str"
Expand Down Expand Up @@ -1968,13 +1969,10 @@ impl String {
/// this function is ideally used for data that lives for the remainder of the program's life,
/// as dropping the returned reference will cause a memory leak.
///
/// It does not reallocate or shrink the `String`,
/// so the leaked allocation may include unused capacity that is not part
/// of the returned slice. The advantage of this is that it avoids the potential
/// reallocation that [`shrink_to_fit`] may perform.
///
/// If you want to discard excess capacity, call [`into_boxed_str`],
/// and then [`Box::leak`] instead.
/// It does not reallocate or shrink the `String`, so the leaked allocation may include unused
/// capacity that is not part of the returned slice. If you want to discard excess capacity,
/// call [`into_boxed_str`], and then [`Box::leak`] instead. However, keep in mind that
/// trimming the capacity may result in a reallocation and copy.
///
/// [`into_boxed_str`]: Self::into_boxed_str
///
Expand Down

0 comments on commit 22fc094

Please sign in to comment.