pub enum FileType {
BlockDevice,
CharDevice,
Directory,
Pipe,
Symlink,
RegularFile,
Socket,
Unknown,
}Expand description
Represents the type of a file in the filesystem, tiny enum
Variants§
Implementations§
Source§impl FileType
impl FileType
Sourcepub const fn from_dtype(d_type: u8) -> Self
pub const fn from_dtype(d_type: u8) -> Self
Converts a libc file type to a FileType
I would prefer to use this function instead of from_dtype_fallback but some some filesystems do not use d_type or set to 0
on EXT4/BTRFS this is fine however its not guaranteed so this is not really useful.
pub const fn is_dir(&self) -> bool
pub const fn is_regular_file(&self) -> bool
pub const fn is_symlink(&self) -> bool
pub const fn is_block_device(&self) -> bool
pub const fn is_char_device(&self) -> bool
pub const fn is_pipe(&self) -> bool
pub const fn is_socket(&self) -> bool
pub const fn is_unknown(&self) -> bool
Sourcepub const fn is_traversible(&self) -> bool
pub const fn is_traversible(&self) -> bool
Returns true if the file type is traversible, i.e. a directory or sy symlink.
Sourcepub fn from_dtype_fallback(d_type: u8, file_path: &[u8]) -> Self
pub fn from_dtype_fallback(d_type: u8, file_path: &[u8]) -> Self
this is a fallback for when we can’t get the file type from libc this can happen on funky filesystems like NTFS/XFS, BTRFS/ext4 work fine.
Sourcepub fn from_bytes(file_path: &[u8]) -> Self
pub fn from_bytes(file_path: &[u8]) -> Self
uses a lstat call to get the file type, more costly but more accurate this is used when we can’t get the file type from dirent64 due to funky filesystems
pub const fn from_mode(mode: mode_t) -> Self
Sourcepub fn from_path<P: AsRef<Path>>(path_start: P) -> Self
pub fn from_path<P: AsRef<Path>>(path_start: P) -> Self
converts a FileType from a path via stdlib’s Path this is handy for verification, its not meant for use within iteration
Sourcepub const fn from_stat(stat: &stat) -> Self
pub const fn from_stat(stat: &stat) -> Self
Converts a libc::stat to a FileType
This is useful for when you have a stat struct and want to get the file type
without having to call lstat again.
Sourcepub const fn d_type_value(&self) -> u8
pub const fn d_type_value(&self) -> u8
Returns the corresponding libc dirent d_type value
Trait Implementations§
Source§impl Ord for FileType
impl Ord for FileType
Source§impl PartialOrd for FileType
impl PartialOrd for FileType
impl Copy for FileType
impl Eq for FileType
impl StructuralPartialEq 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 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> CloneUnsized for Twhere
T: Clone,
impl<T> CloneUnsized for Twhere
T: Clone,
Source§fn unsized_clone_from(&mut self, source: &T)
fn unsized_clone_from(&mut self, source: &T)
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more