@@ -188,6 +188,16 @@ impl OsString {
188
188
/// in the given `OsString`.
189
189
///
190
190
/// 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
+ /// ```
191
201
#[ stable( feature = "osstring_simple_functions" , since = "1.9.0" ) ]
192
202
pub fn reserve ( & mut self , additional : usize ) {
193
203
self . inner . reserve ( additional)
@@ -200,18 +210,56 @@ impl OsString {
200
210
/// Note that the allocator may give the collection more space than it
201
211
/// requests. Therefore capacity can not be relied upon to be precisely
202
212
/// 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
+ /// ```
203
223
#[ stable( feature = "osstring_simple_functions" , since = "1.9.0" ) ]
204
224
pub fn reserve_exact ( & mut self , additional : usize ) {
205
225
self . inner . reserve_exact ( additional)
206
226
}
207
227
208
228
/// 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
+ /// ```
209
245
#[ unstable( feature = "osstring_shrink_to_fit" , issue = "40421" ) ]
210
246
pub fn shrink_to_fit ( & mut self ) {
211
247
self . inner . shrink_to_fit ( )
212
248
}
213
249
214
250
/// 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
+ /// ```
215
263
#[ unstable( feature = "into_boxed_os_str" , issue = "40380" ) ]
216
264
pub fn into_boxed_os_str ( self ) -> Box < OsStr > {
217
265
unsafe { mem:: transmute ( self . inner . into_box ( ) ) }
@@ -398,6 +446,16 @@ impl OsStr {
398
446
/// Copies the slice into an owned [`OsString`].
399
447
///
400
448
/// [`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
+ /// ```
401
459
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
402
460
pub fn to_os_string ( & self ) -> OsString {
403
461
OsString { inner : self . inner . to_owned ( ) }
0 commit comments