Struct FileType
pub struct FileType(pub(in ::fs) FileType);
A structure representing a type of file with accessors for each file type.
It is returned by Metadata::file_type method.
Fields
0: FileType
Implementations
impl FileType
fn is_dir(&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) -> 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) -> 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(()) }
Trait Implementations
impl AsInner<FileType> for FileType
fn as_inner(&self) -> &FileType
impl Clone for FileType
fn clone(&self) -> FileType
impl Copy for FileType
impl Debug for FileType
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Eq for FileType
fn assert_fields_are_eq(&self)
impl FileTypeExt for FileType
fn is_block_device(&self) -> boolfn is_char_device(&self) -> boolfn is_socket(&self) -> bool
impl FileTypeExt for FileType
fn is_block_device(&self) -> boolfn is_char_device(&self) -> boolfn is_fifo(&self) -> boolfn is_socket(&self) -> bool
impl FileTypeExt for FileType
fn is_symlink_dir(&self) -> boolfn is_symlink_file(&self) -> bool
impl Hash for FileType
fn hash<__H: Hasher>(&self, state: &mut __H)
impl PartialEq for FileType
fn eq(&self, other: &FileType) -> bool
impl StructuralPartialEq for FileType
impl TrivialClone for FileType
Auto Trait Implementations
impl Freeze for FileType
impl RefUnwindSafe for FileType
impl Send for FileType
impl Sync for FileType
impl Unpin for FileType
impl UnsafeUnpin for FileType
impl UnwindSafe for FileType
Blanket Implementations
impl<T> Any for FileType
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for FileType
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for FileType
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for FileType
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for FileType
fn from(t: T) -> TReturns the argument unchanged.
impl<T> Printable for FileType
where
T: Copy + Debug,
impl<T> SizeHint for FileType
where
T: ?Sized,
fn lower_bound(&self) -> usizefn upper_bound(&self) -> Option<usize>
impl<T> SizedTypeProperties for FileType
impl<T> ToOwned for FileType
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T, U> Into<U> for FileType
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for FileType
where
U: Into<T>,
type Error = Infallible;fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto<U> for FileType
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>