@@ -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 ( ) )
@@ -839,14 +855,56 @@ impl Permissions {
839
855
840
856
impl FileType {
841
857
/// Test whether this file type represents a directory.
858
+ ///
859
+ /// # Examples
860
+ ///
861
+ /// ```
862
+ /// # fn foo() -> std::io::Result<()> {
863
+ /// use std::fs;
864
+ ///
865
+ /// let metadata = try!(fs::metadata("foo.txt"));
866
+ /// let file_type = metadata.file_type();
867
+ ///
868
+ /// assert_eq!(file_type.is_dir(), false);
869
+ /// # Ok(())
870
+ /// # }
871
+ /// ```
842
872
#[ stable( feature = "file_type" , since = "1.1.0" ) ]
843
873
pub fn is_dir ( & self ) -> bool { self . 0 . is_dir ( ) }
844
874
845
875
/// Test whether this file type represents a regular file.
876
+ ///
877
+ /// # Examples
878
+ ///
879
+ /// ```
880
+ /// # fn foo() -> std::io::Result<()> {
881
+ /// use std::fs;
882
+ ///
883
+ /// let metadata = try!(fs::metadata("foo.txt"));
884
+ /// let file_type = metadata.file_type();
885
+ ///
886
+ /// assert_eq!(file_type.is_file(), true);
887
+ /// # Ok(())
888
+ /// # }
889
+ /// ```
846
890
#[ stable( feature = "file_type" , since = "1.1.0" ) ]
847
891
pub fn is_file ( & self ) -> bool { self . 0 . is_file ( ) }
848
892
849
893
/// Test whether this file type represents a symbolic link.
894
+ ///
895
+ /// # Examples
896
+ ///
897
+ /// ```
898
+ /// # fn foo() -> std::io::Result<()> {
899
+ /// use std::fs;
900
+ ///
901
+ /// let metadata = try!(fs::metadata("foo.txt"));
902
+ /// let file_type = metadata.file_type();
903
+ ///
904
+ /// assert_eq!(file_type.is_symlink(), false);
905
+ /// # Ok(())
906
+ /// # }
907
+ /// ```
850
908
#[ stable( feature = "file_type" , since = "1.1.0" ) ]
851
909
pub fn is_symlink ( & self ) -> bool { self . 0 . is_symlink ( ) }
852
910
}
0 commit comments