@@ -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.
@@ -515,19 +517,79 @@ impl MetadataExt for fs::Metadata {
515
517
fn blocks ( & self ) -> u64 { self . st_blocks ( ) }
516
518
}
517
519
518
- /// Add special unix types (block/char device, fifo and socket)
520
+ /// Add support for special unix types (block/char device, fifo and socket).
519
521
#[ stable( feature = "file_type_ext" , since = "1.5.0" ) ]
520
522
pub trait FileTypeExt {
521
523
/// Returns whether this file type is a block device.
524
+ ///
525
+ /// # Examples
526
+ ///
527
+ /// ```
528
+ /// use std::fs;
529
+ /// use std::os::unix::fs::FileTypeExt;
530
+ ///
531
+ /// # use std::io;
532
+ /// # fn f() -> io::Result<()> {
533
+ /// let meta = fs::metadata("block_device_file")?;
534
+ /// let file_type = meta.file_type();
535
+ /// assert!(file_type.is_block_device());
536
+ /// # Ok(())
537
+ /// # }
538
+ /// ```
522
539
#[ stable( feature = "file_type_ext" , since = "1.5.0" ) ]
523
540
fn is_block_device ( & self ) -> bool ;
524
541
/// Returns whether this file type is a char device.
542
+ ///
543
+ /// # Examples
544
+ ///
545
+ /// ```
546
+ /// use std::fs;
547
+ /// use std::os::unix::fs::FileTypeExt;
548
+ ///
549
+ /// # use std::io;
550
+ /// # fn f() -> io::Result<()> {
551
+ /// let meta = fs::metadata("char_device_file")?;
552
+ /// let file_type = meta.file_type();
553
+ /// assert!(file_type.is_char_device());
554
+ /// # Ok(())
555
+ /// # }
556
+ /// ```
525
557
#[ stable( feature = "file_type_ext" , since = "1.5.0" ) ]
526
558
fn is_char_device ( & self ) -> bool ;
527
559
/// Returns whether this file type is a fifo.
560
+ ///
561
+ /// # Examples
562
+ ///
563
+ /// ```
564
+ /// use std::fs;
565
+ /// use std::os::unix::fs::FileTypeExt;
566
+ ///
567
+ /// # use std::io;
568
+ /// # fn f() -> io::Result<()> {
569
+ /// let meta = fs::metadata("fifo_file")?;
570
+ /// let file_type = meta.file_type();
571
+ /// assert!(file_type.is_fifo());
572
+ /// # Ok(())
573
+ /// # }
574
+ /// ```
528
575
#[ stable( feature = "file_type_ext" , since = "1.5.0" ) ]
529
576
fn is_fifo ( & self ) -> bool ;
530
577
/// Returns whether this file type is a socket.
578
+ ///
579
+ /// # Examples
580
+ ///
581
+ /// ```
582
+ /// use std::fs;
583
+ /// use std::os::unix::fs::FileTypeExt;
584
+ ///
585
+ /// # use std::io;
586
+ /// # fn f() -> io::Result<()> {
587
+ /// let meta = fs::metadata("unix.socket")?;
588
+ /// let file_type = meta.file_type();
589
+ /// assert!(file_type.is_socket());
590
+ /// # Ok(())
591
+ /// # }
592
+ /// ```
531
593
#[ stable( feature = "file_type_ext" , since = "1.5.0" ) ]
532
594
fn is_socket ( & self ) -> bool ;
533
595
}
@@ -540,7 +602,9 @@ impl FileTypeExt for fs::FileType {
540
602
fn is_socket ( & self ) -> bool { self . as_inner ( ) . is ( libc:: S_IFSOCK ) }
541
603
}
542
604
543
- /// Unix-specific extension methods for `fs::DirEntry`
605
+ /// Unix-specific extension methods for [`fs::DirEntry`].
606
+ ///
607
+ /// [`fs::DirEntry`]: ../../../../std/fs/struct.DirEntry.html
544
608
#[ stable( feature = "dir_entry_ext" , since = "1.1.0" ) ]
545
609
pub trait DirEntryExt {
546
610
/// Returns the underlying `d_ino` field in the contained `dirent`
@@ -600,7 +664,9 @@ pub fn symlink<P: AsRef<Path>, Q: AsRef<Path>>(src: P, dst: Q) -> io::Result<()>
600
664
}
601
665
602
666
#[ stable( feature = "dir_builder" , since = "1.6.0" ) ]
603
- /// An extension trait for `fs::DirBuilder` for unix-specific options.
667
+ /// An extension trait for [`fs::DirBuilder`] for unix-specific options.
668
+ ///
669
+ /// [`fs::DirBuilder`]: ../../../../std/fs/struct.DirBuilder.html
604
670
pub trait DirBuilderExt {
605
671
/// Sets the mode to create new directories with. This option defaults to
606
672
/// 0o777.
0 commit comments