Enum file_type_enum::FileType
source · pub enum FileType {
Regular,
Directory,
Symlink,
BlockDevice,
CharDevice,
Fifo,
Socket,
}
Expand description
An enum with a variant for each file type.
match file_type {
FileType::Regular => {},
FileType::Directory => {},
FileType::Symlink => {},
FileType::BlockDevice => {}, // unix only
FileType::CharDevice => {}, // unix only
FileType::Fifo => {}, // unix only
FileType::Socket => {}, // unix only
}
Variants§
Regular
A regular file.
Directory
A directory, folder of files.
Symlink
A symbolic link, points to another path.
BlockDevice
Unix block device.
CharDevice
Unix char device.
Fifo
Unix FIFO.
Socket
Unix socket.
Implementations§
source§impl FileType
impl FileType
sourcepub fn read_at(path: impl AsRef<Path>) -> Result<Self>
pub fn read_at(path: impl AsRef<Path>) -> Result<Self>
Reads a FileType
from a path.
This function follows symlinks, so it can never return a FileType::Symlink
.
Errors
- Path does not exist, or
- Current user lacks permissions to read
fs::Metadata
ofpath
.
sourcepub fn symlink_read_at(path: impl AsRef<Path>) -> Result<Self>
pub fn symlink_read_at(path: impl AsRef<Path>) -> Result<Self>
Reads a FileType
from a path, considers symlinks.
This function does not follow symlinks, therefore, FileType::Symlink
can be returned, if
you don’t want that, see FileType::read_at
.
Errors
- Path does not exist, or
- Current user lacks permissions to read
fs::Metadata
ofpath
.
sourcepub fn is_regular(&self) -> bool
pub fn is_regular(&self) -> bool
Returns true if is a FileType::Regular
.
sourcepub fn is_directory(&self) -> bool
pub fn is_directory(&self) -> bool
Returns true if is a FileType::Directory
.
sourcepub fn is_symlink(&self) -> bool
pub fn is_symlink(&self) -> bool
Returns true if is a FileType::Symlink
.
sourcepub fn is_block_device(&self) -> bool
pub fn is_block_device(&self) -> bool
Returns true if is a FileType::BlockDevice
.
sourcepub fn is_char_device(&self) -> bool
pub fn is_char_device(&self) -> bool
Returns true if is a FileType::CharDevice
.
sourcepub fn is_fifo(&self) -> bool
pub fn is_fifo(&self) -> bool
Returns true if is a FileType::Fifo
.
sourcepub fn is_socket(&self) -> bool
pub fn is_socket(&self) -> bool
Returns true if is a FileType::Socket
.
Trait Implementations§
source§impl Ord for FileType
impl Ord for FileType
source§impl PartialEq for FileType
impl PartialEq for FileType
source§impl PartialOrd for FileType
impl PartialOrd for FileType
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl Copy for FileType
impl Eq for FileType
impl StructuralEq for FileType
impl StructuralPartialEq for FileType
Auto Trait Implementations§
impl RefUnwindSafe for FileType
impl Send for FileType
impl Sync for FileType
impl Unpin for FileType
impl UnwindSafe for FileType
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more