[−][src]Enum file_structure::FileType
Variants
Symlink(PathBuf)Implementations
impl FileType[src]
pub fn from_path(
path: impl AsRef<Path>,
follow_symlinks: bool
) -> FSResult<Self>[src]
path: impl AsRef<Path>,
follow_symlinks: bool
) -> FSResult<Self>
Recursively creates FileType from path.
Example
use file_structure::{FileType, FSError}; fn main() -> Result<(), FSError> { let file_type = FileType::from_path("src/", true)?; if let FileType::Directory(ref children) = file_type { println!("We found {} files!", children.len()); // vec.len() for child in children { println!("{:#?}", child); } } Ok(()) }
Useful when
Notes:
If follow_symlinks is true, when gathering information about the
file type, this function will make a system call that
traverses paths until there is no symlink left, this means that the
return type in this case can never be the variant
FileType::Symlink(_), if you want to read from the path and also check
if it is a symlink, set follow_symlinks to false.
For each directory, call the function recursively.
See also from_path_shallow.
pub fn from_path_shallow(
path: impl AsRef<Path>,
follow_symlink: bool
) -> FSResult<Self>[src]
path: impl AsRef<Path>,
follow_symlink: bool
) -> FSResult<Self>
Similar to from_path, but leaves Directory and Symlink empty.
This function is guaranteed to only make one syscall for the FileType,
this means that it cannot read all the elements from inside of the
directories.
This is useful when you want to make a quick check on a file type without going into it's thousand subsequent files, that would take a lot of time.
Example:
use file_structure::{FileType, FSError}; fn main() -> Result<(), FSError> { let file_type = FileType::from_path_shallow("/sbin", true)?; if !file_type.is_dir() { println!("There's something wrong with our file system."); } Ok(()) }
pub fn is_regular(&self) -> bool[src]
Checks variant FileType::Regular(_)
pub fn is_dir(&self) -> bool[src]
Checks variant FileType::Directory(_)
pub fn is_symlink(&self) -> bool[src]
Checks variant FileType::Symlink(_)
pub fn children(&self) -> Option<&Vec<File>>[src]
Shorthand for unpacking FileType::Directory(ref children)
Trait Implementations
impl Clone for FileType[src]
impl Debug for FileType[src]
impl Default for FileType[src]
impl Display for FileType[src]
impl Eq for FileType[src]
impl Hash for FileType[src]
fn hash<__H: Hasher>(&self, state: &mut __H)[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher, 1.3.0[src]
H: Hasher,
impl Ord for FileType[src]
fn cmp(&self, other: &FileType) -> Ordering[src]
#[must_use]fn max(self, other: Self) -> Self1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self[src]
impl PartialEq<FileType> for FileType[src]
impl PartialOrd<FileType> for FileType[src]
fn partial_cmp(&self, other: &FileType) -> Option<Ordering>[src]
fn lt(&self, other: &FileType) -> bool[src]
fn le(&self, other: &FileType) -> bool[src]
fn gt(&self, other: &FileType) -> bool[src]
fn ge(&self, other: &FileType) -> bool[src]
impl StructuralEq for FileType[src]
impl StructuralPartialEq for FileType[src]
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
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T[src]
fn clone_into(&self, target: &mut T)[src]
impl<T> ToString for T where
T: Display + ?Sized, [src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,