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 (e.g. ‘.txt’, ‘.rs’, ‘.zip’).
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
sourceimpl FileType
impl FileType
sourcepub fn from_path(path: impl AsRef<Path>) -> Result<Self>
pub fn from_path(path: impl AsRef<Path>) -> Result<Self>
Reads a FileType
from a path.
This function follows symlinks, so it can never return a FileType::Symlink
.
Example
use file_type_enum::FileType;
use std::io;
fn main() -> io::Result<()> {
let is_everything_alright = FileType::from_path("/dev/tty")?.is_char_device();
Ok(())
}
Errors
- Path does not exist, or
- Current user lacks permissions to read
fs::Metadata
ofpath
.
sourcepub fn from_symlink_path(path: impl AsRef<Path>) -> Result<Self>
pub fn from_symlink_path(path: impl AsRef<Path>) -> Result<Self>
Reads a FileType
from a path, considers symlinks.
This function does not follow symlinks, so the result can be the variant FileType::Symlink
too, unlike FileType::from_path
.
Example
use file_type_enum::FileType;
let path = "/dev/stdout";
let file_type = FileType::from_symlink_path(path).unwrap();
println!("There's a {file_type} at {path}");
// Out: "There's a symlink at /dev/stdout"
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
sourceimpl Ord for FileType
impl Ord for FileType
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl PartialOrd<FileType> for FileType
impl PartialOrd<FileType> for FileType
sourcefn partial_cmp(&self, other: &FileType) -> Option<Ordering>
fn partial_cmp(&self, other: &FileType) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn 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 more
impl 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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more