[][src]Enum file_structure::FileType

pub enum FileType {
    Regular,
    Directory(Vec<File>),
    Symlink(PathBuf),
}

Variants

Regular
Directory(Vec<File>)

Implementations

impl FileType[src]

pub fn from_path(
    path: impl AsRef<Path>,
    follow_symlinks: bool
) -> FSResult<Self>
[src]

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]

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(_)

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]

impl Ord for FileType[src]

impl PartialEq<FileType> for FileType[src]

impl PartialOrd<FileType> for FileType[src]

impl StructuralEq for FileType[src]

impl StructuralPartialEq for FileType[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.