@@ -251,6 +251,14 @@ impl Hash for OsString {
251
251
252
252
impl OsStr {
253
253
/// Coerces into an `OsStr` slice.
254
+ ///
255
+ /// # Examples
256
+ ///
257
+ /// ```
258
+ /// use std::ffi::OsStr;
259
+ ///
260
+ /// let os_str = OsStr::new("foo");
261
+ /// ```
254
262
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
255
263
pub fn new < S : AsRef < OsStr > + ?Sized > ( s : & S ) -> & OsStr {
256
264
s. as_ref ( )
@@ -283,6 +291,18 @@ impl OsStr {
283
291
}
284
292
285
293
/// Checks whether the `OsStr` is empty.
294
+ ///
295
+ /// # Examples
296
+ ///
297
+ /// ```
298
+ /// use std::ffi::OsStr;
299
+ ///
300
+ /// let os_str = OsStr::new("");
301
+ /// assert!(os_str.is_empty());
302
+ ///
303
+ /// let os_str = OsStr::new("foo");
304
+ /// assert!(!os_str.is_empty());
305
+ /// ```
286
306
#[ stable( feature = "osstring_simple_functions" , since = "1.9.0" ) ]
287
307
pub fn is_empty ( & self ) -> bool {
288
308
self . inner . inner . is_empty ( )
@@ -296,6 +316,18 @@ impl OsStr {
296
316
/// other methods like `OsString::with_capacity` to avoid reallocations.
297
317
///
298
318
/// See `OsStr` introduction for more information about encoding.
319
+ ///
320
+ /// # Examples
321
+ ///
322
+ /// ```
323
+ /// use std::ffi::OsStr;
324
+ ///
325
+ /// let os_str = OsStr::new("");
326
+ /// assert_eq!(os_str.len(), 0);
327
+ ///
328
+ /// let os_str = OsStr::new("foo");
329
+ /// assert_eq!(os_str.len(), 3);
330
+ /// ```
299
331
#[ stable( feature = "osstring_simple_functions" , since = "1.9.0" ) ]
300
332
pub fn len ( & self ) -> usize {
301
333
self . inner . inner . len ( )
0 commit comments