Struct FileType
struct FileType(_)
A structure representing a type of file with accessors for each file type.
It is returned by Metadata::file_type method.
Implementations
impl FileType
fn is_dir(self: &Self) -> boolTests whether this file type represents a directory. The result is mutually exclusive to the results of
is_fileandis_symlink; only zero or one of these tests may pass.Examples
fn main() -> std::io::Result<()> { use std::fs; let metadata = fs::metadata("foo.txt")?; let file_type = metadata.file_type(); assert_eq!(file_type.is_dir(), false); Ok(()) }fn is_file(self: &Self) -> boolTests whether this file type represents a regular file. The result is mutually exclusive to the results of
is_dirandis_symlink; only zero or one of these tests may pass.When the goal is simply to read from (or write to) the source, the most reliable way to test the source can be read (or written to) is to open it. Only using
is_filecan break workflows likediff <( prog_a )on a Unix-like system for example. SeeFile::openorOpenOptions::openfor more information.Examples
fn main() -> std::io::Result<()> { use std::fs; let metadata = fs::metadata("foo.txt")?; let file_type = metadata.file_type(); assert_eq!(file_type.is_file(), true); Ok(()) }fn is_symlink(self: &Self) -> boolTests whether this file type represents a symbolic link. The result is mutually exclusive to the results of
is_dirandis_file; only zero or one of these tests may pass.The underlying
Metadatastruct needs to be retrieved with thefs::symlink_metadatafunction and not thefs::metadatafunction. Thefs::metadatafunction follows symbolic links, sois_symlinkwould always returnfalsefor the target file.Examples
use std::fs; fn main() -> std::io::Result<()> { let metadata = fs::symlink_metadata("foo.txt")?; let file_type = metadata.file_type(); assert_eq!(file_type.is_symlink(), false); Ok(()) }
impl Clone for FileType
fn clone(self: &Self) -> FileType
impl Copy for FileType
impl Debug for FileType
fn fmt(self: &Self, f: &mut fmt::Formatter<'_>) -> fmt::Result
impl Eq for FileType
impl FileTypeExt for fs::FileType
fn is_symlink_dir(self: &Self) -> boolfn is_symlink_file(self: &Self) -> bool
impl FileTypeExt for fs::FileType
fn is_block_device(self: &Self) -> boolfn is_char_device(self: &Self) -> boolfn is_fifo(self: &Self) -> boolfn is_socket(self: &Self) -> bool
impl FileTypeExt for fs::FileType
fn is_block_device(self: &Self) -> boolfn is_char_device(self: &Self) -> boolfn is_socket(self: &Self) -> bool
impl Freeze for FileType
impl Hash for FileType
fn hash<__H: $crate::hash::Hasher>(self: &Self, state: &mut __H)
impl PartialEq for FileType
fn eq(self: &Self, other: &FileType) -> bool
impl RefUnwindSafe for FileType
impl Send for FileType
impl StructuralPartialEq for FileType
impl Sync for FileType
impl Unpin for FileType
impl UnwindSafe for FileType
impl<T> Any for FileType
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for FileType
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for FileType
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for FileType
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for FileType
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for FileType
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T, U> Into for FileType
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for FileType
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for FileType
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>