Skip to content

Commit 56a89f5

Browse files
Rollup merge of rust-lang#35076 - GuillaumeGomez:file_type_docs, r=steveklabnik
Add doc examples for FileType struct Part of rust-lang#29356. r? @steveklabnik
2 parents 4944952 + 3e46c9d commit 56a89f5

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())
@@ -839,14 +855,56 @@ impl Permissions {
839855

840856
impl FileType {
841857
/// 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+
/// ```
842872
#[stable(feature = "file_type", since = "1.1.0")]
843873
pub fn is_dir(&self) -> bool { self.0.is_dir() }
844874

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

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

0 commit comments

Comments
 (0)