pub trait Entry {
// Required methods
fn into_path(self) -> PathBuf
where Self: Sized;
fn path(&self) -> &Path;
fn root_relative_paths(&self) -> (&Path, &Path);
fn metadata(&self) -> Result<Metadata, WalkError>;
fn file_type(&self) -> FileType;
fn depth(&self) -> usize;
}
walk
only.Expand description
Describes a file yielded from a FileIterator
.
Required Methods§
sourcefn root_relative_paths(&self) -> (&Path, &Path)
fn root_relative_paths(&self) -> (&Path, &Path)
Gets the root and relative paths.
The root path is the path to the walked directory from which the file entry has been read. The relative path is the remainder of the file path of the entry (the path relative to the root directory). Both the root and relative paths may be empty.
The root and relative paths can differ significantly depending on the way a directory is
walked, in particular when using a Glob
. The following table describes some example
paths when using Glob::walk
.
Glob Expression | Directory | Entry Path | Root | Relative |
---|---|---|---|---|
**/*.txt | /home/user | /home/user/notes.txt | /home/user | notes.txt |
projects/**/src/**/*.rs | . | ./projects/fibonacci/src/main.rs | . | projects/fibonacci/src/main.rs |
/var/log/**/*.log | . | /var/log/pacman.log | /var/log/pacman.log |
See also GlobWalker::root_prefix_paths
.
sourcefn metadata(&self) -> Result<Metadata, WalkError>
fn metadata(&self) -> Result<Metadata, WalkError>
Gets the Metadata
of the file.
On some platforms, this requires an additional read from the file system.
sourcefn file_type(&self) -> FileType
fn file_type(&self) -> FileType
Gets the type of the file (regular vs. directory).
Prefer this function over metadata
if only the file type is needed, as this information
is cached.
sourcefn depth(&self) -> usize
fn depth(&self) -> usize
Gets the depth of the file path from the root.
The root path is the path to the walked directory from which the file entry has been read.
Use root_relative_paths
to get the root path.