File tree 1 file changed +7
-3
lines changed
1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -1940,8 +1940,9 @@ impl String {
1940
1940
1941
1941
/// Converts this `String` into a <code>[Box]<[str]></code>.
1942
1942
///
1943
- /// This will drop any excess capacity.
1943
+ /// Before doing the conversion, this method discards excess capacity like [`shrink_to_fit`] .
1944
1944
///
1945
+ /// [`shrink_to_fit`]: String::shrink_to_fit
1945
1946
/// [str]: prim@str "str"
1946
1947
///
1947
1948
/// # Examples
@@ -1969,8 +1970,11 @@ impl String {
1969
1970
///
1970
1971
/// It does not reallocate or shrink the `String`,
1971
1972
/// so the leaked allocation may include unused capacity that is not part
1972
- /// of the returned slice. If you don't want that, call [`into_boxed_str`],
1973
- /// and then [`Box::leak`].
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.
1974
1978
///
1975
1979
/// [`into_boxed_str`]: Self::into_boxed_str
1976
1980
///
You can’t perform that action at this time.
0 commit comments