pub struct FileTree {
    pub path: PathBuf,
    pub file_type: FileTreeType,
}
Expand description

A filesystem tree recursive type.

Fields

path: PathBuf

The filename of this file.

file_type: FileTreeType

The filetype of this file.

Implementations

Creates a FileTree::Regular from arguments.

Creates a FileTree::Directory from arguments.

Creates a FileTree::Symlink from arguments.

Collects a Vec of FileTree from path that is a directory.

Collects a Vec of FileTree from path that is a directory, entries can be symlinks.

Collects a Vec of FileTree from path that is a directory.

Collects a Vec of FileTree from path that is a directory, entries can be symlinks.

Builds a FileTree from path, follows symlinks.

Similar to from_path_symlink.

If file at path is a regular file, will return a FileTree::Regular. If file at path is a directory file, FileTree::Directory (with .children).

Errors:
  • If Io::Error from fs::metadata(path)
  • If it is a directory, and Io::Error from fs::read_dir(path) iterator usage
  • If unexpected file type at path

This function traverses symlinks until final destination, and then reads it, so it can never return Ok(FileTree::Symlink { .. ]}), if you wish otherwise, use FileTree::from_path_symlink instead.

Builds a FileTree from path, follows symlinks.

Similar to from_path_symlink.

If file at path is a regular file, will return a FileTree::Regular. If file at path is a directory file, FileTree::Directory (with children field). If file at path is a symlink file, FileTree::Symlink (with target_path field).

Errors:
  • If Io::Error from fs::metadata(path)
  • If it is a directory, and Io::Error from fs::read_dir(path) iterator usage
  • If it is a symlink, and Io::Error from fs::read_link(path)
  • If unexpected file type at path

If you wish to traverse symlinks until final destination, instead, use FileTree::from_path.

cd into path, run from_path, and come back.

TODO explain here why this is useful

cd into path, run from_path_symlink, and come back.

TODO explain here why this is useful

Splits a Path components into a FileTree.

Returns None if the string is empty.

Can only build Regular and Directory, not symlink.

Example:

use fs_tree::FileTree;

let result = FileTree::from_path_text(".config/i3/file");

let expected = {
    FileTree::new_directory(
        ".config/",
        vec![FileTree::new_directory(
            ".config/i3/",
            vec![FileTree::new_regular(".config/i3/file")],
        )],
    )
};

assert_eq!(result, Some(expected));

More generic version of FileTree::from_path_text.

Iterator of all FileTrees in the structure

Shorthand for self.files().paths(), see link to .paths() method

Fix relative paths from each node piece.

If you manually build a structure like:

"a": [
    "b": [
        "c",
    ]
]

Using the create methods, then you need to run this function to make them relative paths.

"a": [
    "a/b": [
        "a/b/c",
    ]
]

Then, you can access any of the files only by looking at their path.

Makes all paths in the tree absolute.

Errors:

In case std::fs::canonicalize fails at any path, this function will stop and return an IoError, leave the tree in a mixed state in terms of canonical paths.

Merge this tree with other FileTree.

This function is currently experimental and likely to change in future versions.

Errors:

This errs if:

  • The trees have different roots and thus cannot be merged.
  • There are file conflicts.

Reference to children vec if self.is_directory().

Reference to children vec if self.is_directory(), mutable.

Reference to target_path if self.is_symlink().

Reference to target_path if self.is_symlink(), mutable.

Apply a closure for each direct child of this FileTree.

Only 1 level deep.

Apply a closure to all direct and indirect descendants inside of this structure.

Calls recursively for all levels.

Apply a closure to all direct and indirect descendants inside, also includes root.

Calls recursively for all levels.

Gets a reference to the file path to this node.

Gets a mutable reference to the file path to this node.

Shorthand for file.file_type.is_regular()

Shorthand for file.file_type.is_dir()

Shorthand for file.file_type.is_symlink()

Turn this node of the tree into a regular file.

Beware the possible recursive drop of nested nodes if this node was a directory.

Turn this node of the tree into a directory.

Beware the possible recursive drop of nested nodes if this node was a directory.

Turn this node of the tree into a symlink.

Beware the possible recursive drop of nested nodes if this node was a directory.

Checks if the FileTree file type is the same as other FileTree.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.