Rollup merge of #40410 - clarcharr:os_string_shrink_to_fit, r=alexcrichton

OsString::shrink_to_fit.

Considering how the other capacity-related methods are there, I found it odd that this one wasn't included.

Will create a tracking issue once I get an OK on this.
This commit is contained in:
Alex Crichton 2017-03-10 16:51:46 -06:00
commit f4b4e097a6
5 changed files with 25 additions and 0 deletions

View File

@ -205,6 +205,12 @@ impl OsString {
self.inner.reserve_exact(additional)
}
/// Shrinks the capacity of the `OsString` to match its length.
#[unstable(feature = "osstring_shrink_to_fit", issue = "40421")]
pub fn shrink_to_fit(&mut self) {
self.inner.shrink_to_fit()
}
/// Converts this `OsString` into a boxed `OsStr`.
#[unstable(feature = "into_boxed_os_str", issue = "0")]
pub fn into_boxed_os_str(self) -> Box<OsStr> {

View File

@ -83,6 +83,11 @@ impl Buf {
self.inner.reserve_exact(additional)
}
#[inline]
pub fn shrink_to_fit(&mut self) {
self.inner.shrink_to_fit()
}
pub fn as_slice(&self) -> &Slice {
unsafe { mem::transmute(&*self.inner) }
}

View File

@ -83,6 +83,11 @@ impl Buf {
self.inner.reserve_exact(additional)
}
#[inline]
pub fn shrink_to_fit(&mut self) {
self.inner.shrink_to_fit()
}
pub fn as_slice(&self) -> &Slice {
unsafe { mem::transmute(&*self.inner) }
}

View File

@ -89,6 +89,10 @@ impl Buf {
self.inner.reserve_exact(additional)
}
pub fn shrink_to_fit(&mut self) {
self.inner.shrink_to_fit()
}
#[inline]
pub fn into_box(self) -> Box<Slice> {
unsafe { mem::transmute(self.inner.into_box()) }

View File

@ -236,6 +236,11 @@ impl Wtf8Buf {
self.bytes.reserve_exact(additional)
}
#[inline]
pub fn shrink_to_fit(&mut self) {
self.bytes.shrink_to_fit()
}
/// Returns the number of bytes that this string buffer can hold without reallocating.
#[inline]
pub fn capacity(&self) -> usize {