Skip to content

Commit 22fc094

Browse files
authored
Update string.rs
1 parent 9c56d0c commit 22fc094

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

library/alloc/src/string.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -1941,6 +1941,7 @@ impl String {
19411941
/// Converts this `String` into a <code>[Box]<[str]></code>.
19421942
///
19431943
/// Before doing the conversion, this method discards excess capacity like [`shrink_to_fit`].
1944+
/// Note that the [`shrink_to_fit`] call may reallocate and copy the bytes of the string.
19441945
///
19451946
/// [`shrink_to_fit`]: String::shrink_to_fit
19461947
/// [str]: prim@str "str"
@@ -1968,13 +1969,10 @@ impl String {
19681969
/// this function is ideally used for data that lives for the remainder of the program's life,
19691970
/// as dropping the returned reference will cause a memory leak.
19701971
///
1971-
/// It does not reallocate or shrink the `String`,
1972-
/// so the leaked allocation may include unused capacity that is not part
1973-
/// of the returned slice. The advantage of this is that it avoids the potential
1974-
/// reallocation that [`shrink_to_fit`] may perform.
1975-
///
1976-
/// If you want to discard excess capacity, call [`into_boxed_str`],
1977-
/// and then [`Box::leak`] instead.
1972+
/// It does not reallocate or shrink the `String`, so the leaked allocation may include unused
1973+
/// capacity that is not part of the returned slice. If you want to discard excess capacity,
1974+
/// call [`into_boxed_str`], and then [`Box::leak`] instead. However, keep in mind that
1975+
/// trimming the capacity may result in a reallocation and copy.
19781976
///
19791977
/// [`into_boxed_str`]: Self::into_boxed_str
19801978
///

0 commit comments

Comments
 (0)