]> git.lizzy.rs Git - rust.git/commitdiff
Add doc example for `OsString::shrink_to_fit`.
authorCorey Farwell <coreyf@rwell.org>
Sun, 12 Mar 2017 20:22:12 +0000 (16:22 -0400)
committerCorey Farwell <coreyf@rwell.org>
Tue, 14 Mar 2017 13:30:00 +0000 (09:30 -0400)
src/libstd/ffi/os_str.rs

index d960d76146fe967e3f3b1bc5b62ef396adac005c..9da6eca34086e01a879acdeef4096439f224ef57 100644 (file)
@@ -226,6 +226,22 @@ pub fn reserve_exact(&mut self, additional: usize) {
     }
 
     /// Shrinks the capacity of the `OsString` to match its length.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// #![feature(osstring_shrink_to_fit)]
+    ///
+    /// use std::ffi::OsString;
+    ///
+    /// let mut s = OsString::from("foo");
+    ///
+    /// s.reserve(100);
+    /// assert!(s.capacity() >= 100);
+    ///
+    /// s.shrink_to_fit();
+    /// assert_eq!(3, s.capacity());
+    /// ```
     #[unstable(feature = "osstring_shrink_to_fit", issue = "40421")]
     pub fn shrink_to_fit(&mut self) {
         self.inner.shrink_to_fit()