@@ -156,7 +156,10 @@ pub struct OpenOptions(fs_imp::OpenOptions);
156
156
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
157
157
pub struct Permissions ( fs_imp:: FilePermissions ) ;
158
158
159
- /// An structure representing a type of file with accessors for each file type.
159
+ /// A structure representing a type of file with accessors for each file type.
160
+ /// It is returned by [`Metadata::file_type`] method.
161
+ ///
162
+ /// [`Metadata::file_type`]: struct.Metadata.html#method.file_type
160
163
#[ stable( feature = "file_type" , since = "1.1.0" ) ]
161
164
#[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug ) ]
162
165
pub struct FileType ( fs_imp:: FileType ) ;
@@ -610,6 +613,19 @@ impl AsInnerMut<fs_imp::OpenOptions> for OpenOptions {
610
613
611
614
impl Metadata {
612
615
/// Returns the file type for this metadata.
616
+ ///
617
+ /// # Examples
618
+ ///
619
+ /// ```
620
+ /// # fn foo() -> std::io::Result<()> {
621
+ /// use std::fs;
622
+ ///
623
+ /// let metadata = try!(fs::metadata("foo.txt"));
624
+ ///
625
+ /// println!("{:?}", metadata.file_type());
626
+ /// # Ok(())
627
+ /// # }
628
+ /// ```
613
629
#[ stable( feature = "file_type" , since = "1.1.0" ) ]
614
630
pub fn file_type ( & self ) -> FileType {
615
631
FileType ( self . 0 . file_type ( ) )
@@ -788,14 +804,56 @@ impl Permissions {
788
804
789
805
impl FileType {
790
806
/// Test whether this file type represents a directory.
807
+ ///
808
+ /// # Examples
809
+ ///
810
+ /// ```
811
+ /// # fn foo() -> std::io::Result<()> {
812
+ /// use std::fs;
813
+ ///
814
+ /// let metadata = try!(fs::metadata("foo.txt"));
815
+ /// let file_type = metadata.file_type();
816
+ ///
817
+ /// assert_eq!(file_type.is_dir(), false);
818
+ /// # Ok(())
819
+ /// # }
820
+ /// ```
791
821
#[ stable( feature = "file_type" , since = "1.1.0" ) ]
792
822
pub fn is_dir ( & self ) -> bool { self . 0 . is_dir ( ) }
793
823
794
824
/// Test whether this file type represents a regular file.
825
+ ///
826
+ /// # Examples
827
+ ///
828
+ /// ```
829
+ /// # fn foo() -> std::io::Result<()> {
830
+ /// use std::fs;
831
+ ///
832
+ /// let metadata = try!(fs::metadata("foo.txt"));
833
+ /// let file_type = metadata.file_type();
834
+ ///
835
+ /// assert_eq!(file_type.is_file(), true);
836
+ /// # Ok(())
837
+ /// # }
838
+ /// ```
795
839
#[ stable( feature = "file_type" , since = "1.1.0" ) ]
796
840
pub fn is_file ( & self ) -> bool { self . 0 . is_file ( ) }
797
841
798
842
/// Test whether this file type represents a symbolic link.
843
+ ///
844
+ /// # Examples
845
+ ///
846
+ /// ```
847
+ /// # fn foo() -> std::io::Result<()> {
848
+ /// use std::fs;
849
+ ///
850
+ /// let metadata = try!(fs::metadata("foo.txt"));
851
+ /// let file_type = metadata.file_type();
852
+ ///
853
+ /// assert_eq!(file_type.is_symlink(), false);
854
+ /// # Ok(())
855
+ /// # }
856
+ /// ```
799
857
#[ stable( feature = "file_type" , since = "1.1.0" ) ]
800
858
pub fn is_symlink ( & self ) -> bool { self . 0 . is_symlink ( ) }
801
859
}
0 commit comments