@@ -20,7 +20,9 @@ use sys;
20
20
use sys_common:: { FromInner , AsInner , AsInnerMut } ;
21
21
use sys:: platform:: fs:: MetadataExt as UnixMetadataExt ;
22
22
23
- /// Unix-specific extensions to `File`
23
+ /// Unix-specific extensions to [`File`].
24
+ ///
25
+ /// [`File`]: ../../../../std/fs/struct.File.html
24
26
#[ stable( feature = "file_offset" , since = "1.15.0" ) ]
25
27
pub trait FileExt {
26
28
/// Reads a number of bytes starting from a given offset.
@@ -269,19 +271,79 @@ impl MetadataExt for fs::Metadata {
269
271
fn blocks ( & self ) -> u64 { self . st_blocks ( ) }
270
272
}
271
273
272
- /// Add special unix types (block/char device, fifo and socket)
274
+ /// Add support for special unix types (block/char device, fifo and socket).
273
275
#[ stable( feature = "file_type_ext" , since = "1.5.0" ) ]
274
276
pub trait FileTypeExt {
275
277
/// Returns whether this file type is a block device.
278
+ ///
279
+ /// # Examples
280
+ ///
281
+ /// ```
282
+ /// use std::fs;
283
+ /// use std::os::unix::fs::FileTypeExt;
284
+ ///
285
+ /// # use std::io;
286
+ /// # fn f() -> io::Result<()> {
287
+ /// let meta = fs::metadata("block_device_file")?;
288
+ /// let file_type = meta.file_type();
289
+ /// assert!(file_type.is_block_device());
290
+ /// # Ok(())
291
+ /// # }
292
+ /// ```
276
293
#[ stable( feature = "file_type_ext" , since = "1.5.0" ) ]
277
294
fn is_block_device ( & self ) -> bool ;
278
295
/// Returns whether this file type is a char device.
296
+ ///
297
+ /// # Examples
298
+ ///
299
+ /// ```
300
+ /// use std::fs;
301
+ /// use std::os::unix::fs::FileTypeExt;
302
+ ///
303
+ /// # use std::io;
304
+ /// # fn f() -> io::Result<()> {
305
+ /// let meta = fs::metadata("char_device_file")?;
306
+ /// let file_type = meta.file_type();
307
+ /// assert!(file_type.is_char_device());
308
+ /// # Ok(())
309
+ /// # }
310
+ /// ```
279
311
#[ stable( feature = "file_type_ext" , since = "1.5.0" ) ]
280
312
fn is_char_device ( & self ) -> bool ;
281
313
/// Returns whether this file type is a fifo.
314
+ ///
315
+ /// # Examples
316
+ ///
317
+ /// ```
318
+ /// use std::fs;
319
+ /// use std::os::unix::fs::FileTypeExt;
320
+ ///
321
+ /// # use std::io;
322
+ /// # fn f() -> io::Result<()> {
323
+ /// let meta = fs::metadata("fifo_file")?;
324
+ /// let file_type = meta.file_type();
325
+ /// assert!(file_type.is_fifo());
326
+ /// # Ok(())
327
+ /// # }
328
+ /// ```
282
329
#[ stable( feature = "file_type_ext" , since = "1.5.0" ) ]
283
330
fn is_fifo ( & self ) -> bool ;
284
331
/// Returns whether this file type is a socket.
332
+ ///
333
+ /// # Examples
334
+ ///
335
+ /// ```
336
+ /// use std::fs;
337
+ /// use std::os::unix::fs::FileTypeExt;
338
+ ///
339
+ /// # use std::io;
340
+ /// # fn f() -> io::Result<()> {
341
+ /// let meta = fs::metadata("unix.socket")?;
342
+ /// let file_type = meta.file_type();
343
+ /// assert!(file_type.is_socket());
344
+ /// # Ok(())
345
+ /// # }
346
+ /// ```
285
347
#[ stable( feature = "file_type_ext" , since = "1.5.0" ) ]
286
348
fn is_socket ( & self ) -> bool ;
287
349
}
@@ -294,7 +356,9 @@ impl FileTypeExt for fs::FileType {
294
356
fn is_socket ( & self ) -> bool { self . as_inner ( ) . is ( libc:: S_IFSOCK ) }
295
357
}
296
358
297
- /// Unix-specific extension methods for `fs::DirEntry`
359
+ /// Unix-specific extension methods for [`fs::DirEntry`].
360
+ ///
361
+ /// [`fs::DirEntry`]: ../../../../std/fs/struct.DirEntry.html
298
362
#[ stable( feature = "dir_entry_ext" , since = "1.1.0" ) ]
299
363
pub trait DirEntryExt {
300
364
/// Returns the underlying `d_ino` field in the contained `dirent`
@@ -354,7 +418,9 @@ pub fn symlink<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<()>
354
418
}
355
419
356
420
#[ stable( feature = "dir_builder" , since = "1.6.0" ) ]
357
- /// An extension trait for `fs::DirBuilder` for unix-specific options.
421
+ /// An extension trait for [`fs::DirBuilder`] for unix-specific options.
422
+ ///
423
+ /// [`fs::DirBuilder`]: ../../../../std/fs/struct.DirBuilder.html
358
424
pub trait DirBuilderExt {
359
425
/// Sets the mode to create new directories with. This option defaults to
360
426
/// 0o777.
0 commit comments