Skip to content

Commit bda57db

Browse files
committed
Add doc example for OsString::shrink_to_fit.
1 parent 5537955 commit bda57db

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/libstd/ffi/os_str.rs

+16
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,22 @@ impl OsString {
226226
}
227227

228228
/// Shrinks the capacity of the `OsString` to match its length.
229+
///
230+
/// # Examples
231+
///
232+
/// ```
233+
/// #![feature(osstring_shrink_to_fit)]
234+
///
235+
/// use std::ffi::OsString;
236+
///
237+
/// let mut s = OsString::from("foo");
238+
///
239+
/// s.reserve(100);
240+
/// assert!(s.capacity() >= 100);
241+
///
242+
/// s.shrink_to_fit();
243+
/// assert_eq!(3, s.capacity());
244+
/// ```
229245
#[unstable(feature = "osstring_shrink_to_fit", issue = "40421")]
230246
pub fn shrink_to_fit(&mut self) {
231247
self.inner.shrink_to_fit()

0 commit comments

Comments
 (0)