@@ -188,6 +188,16 @@ impl OsString {
188188 /// in the given `OsString`.
189189 ///
190190 /// The collection may reserve more space to avoid frequent reallocations.
191+ ///
192+ /// # Examples
193+ ///
194+ /// ```
195+ /// use std::ffi::OsString;
196+ ///
197+ /// let mut s = OsString::new();
198+ /// s.reserve(10);
199+ /// assert!(s.capacity() >= 10);
200+ /// ```
191201 #[ stable( feature = "osstring_simple_functions" , since = "1.9.0" ) ]
192202 pub fn reserve ( & mut self , additional : usize ) {
193203 self . inner . reserve ( additional)
@@ -200,18 +210,56 @@ impl OsString {
200210 /// Note that the allocator may give the collection more space than it
201211 /// requests. Therefore capacity can not be relied upon to be precisely
202212 /// minimal. Prefer reserve if future insertions are expected.
213+ ///
214+ /// # Examples
215+ ///
216+ /// ```
217+ /// use std::ffi::OsString;
218+ ///
219+ /// let mut s = OsString::new();
220+ /// s.reserve_exact(10);
221+ /// assert!(s.capacity() >= 10);
222+ /// ```
203223 #[ stable( feature = "osstring_simple_functions" , since = "1.9.0" ) ]
204224 pub fn reserve_exact ( & mut self , additional : usize ) {
205225 self . inner . reserve_exact ( additional)
206226 }
207227
208228 /// 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+ /// ```
209245 #[ unstable( feature = "osstring_shrink_to_fit" , issue = "40421" ) ]
210246 pub fn shrink_to_fit ( & mut self ) {
211247 self . inner . shrink_to_fit ( )
212248 }
213249
214250 /// Converts this `OsString` into a boxed `OsStr`.
251+ ///
252+ /// # Examples
253+ ///
254+ /// ```
255+ /// #![feature(into_boxed_os_str)]
256+ ///
257+ /// use std::ffi::{OsString, OsStr};
258+ ///
259+ /// let s = OsString::from("hello");
260+ ///
261+ /// let b: Box<OsStr> = s.into_boxed_os_str();
262+ /// ```
215263 #[ unstable( feature = "into_boxed_os_str" , issue = "40380" ) ]
216264 pub fn into_boxed_os_str ( self ) -> Box < OsStr > {
217265 unsafe { mem:: transmute ( self . inner . into_box ( ) ) }
@@ -398,6 +446,16 @@ impl OsStr {
398446 /// Copies the slice into an owned [`OsString`].
399447 ///
400448 /// [`OsString`]: struct.OsString.html
449+ ///
450+ /// # Examples
451+ ///
452+ /// ```
453+ /// use std::ffi::{OsStr, OsString};
454+ ///
455+ /// let os_str = OsStr::new("foo");
456+ /// let os_string = os_str.to_os_string();
457+ /// assert_eq!(os_string, OsString::from("foo"));
458+ /// ```
401459 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
402460 pub fn to_os_string ( & self ) -> OsString {
403461 OsString { inner : self . inner . to_owned ( ) }
0 commit comments