Skip to content

Commit 3e46c9d

Browse files
Add doc examples for FileType struct
1 parent a373b84 commit 3e46c9d

File tree

1 file changed

+59
-1
lines changed

1 file changed

+59
-1
lines changed

src/libstd/fs.rs

+59-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,10 @@ pub struct OpenOptions(fs_imp::OpenOptions);
156156
#[stable(feature = "rust1", since = "1.0.0")]
157157
pub struct Permissions(fs_imp::FilePermissions);
158158

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
160163
#[stable(feature = "file_type", since = "1.1.0")]
161164
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
162165
pub struct FileType(fs_imp::FileType);
@@ -610,6 +613,19 @@ impl AsInnerMut<fs_imp::OpenOptions> for OpenOptions {
610613

611614
impl Metadata {
612615
/// 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+
/// ```
613629
#[stable(feature = "file_type", since = "1.1.0")]
614630
pub fn file_type(&self) -> FileType {
615631
FileType(self.0.file_type())
@@ -788,14 +804,56 @@ impl Permissions {
788804

789805
impl FileType {
790806
/// 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+
/// ```
791821
#[stable(feature = "file_type", since = "1.1.0")]
792822
pub fn is_dir(&self) -> bool { self.0.is_dir() }
793823

794824
/// 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+
/// ```
795839
#[stable(feature = "file_type", since = "1.1.0")]
796840
pub fn is_file(&self) -> bool { self.0.is_file() }
797841

798842
/// 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+
/// ```
799857
#[stable(feature = "file_type", since = "1.1.0")]
800858
pub fn is_symlink(&self) -> bool { self.0.is_symlink() }
801859
}

0 commit comments

Comments
 (0)