Struct fs_more::directory::DirectoryScan

source ·
pub struct DirectoryScan { /* private fields */ }
Expand description

A directory scanner with configurable scan depth and symlink behaviour.

This scanner is able to recursively iterate over the directory as well as optionally follow symbolic links. If, however, you’re looking for something with a bit more features, such as lazy iteration and sorting, consider the walkdir crate.

Implementations§

source§

impl DirectoryScan

source

pub fn scan_with_options<P>( directory_path: P, options: DirectoryScanOptions, ) -> Result<Self, DirectoryScanError>
where P: Into<PathBuf>,

Perform a directory scan.

§Scan depth

Maximum scanning depth can be configured by setting options.maximum_scan_depth.

This scanner can follow symbolic links, see options.follow_symbolic_links for more information.

Regardless of the symbolic link option described above: if directory_path itself is a symbolic link to a directory, the link destination will be resolved before beginning the scan.

source

pub fn files(&self) -> &[PathBuf]

Returns a slice of all scanned files (paths are absolute).

source

pub fn into_files(self) -> Vec<PathBuf>

Consumes self and returns a Vec containing all scanned files (paths are absolute).

If you are also interested in directories, look at Self::files + Self::directories or Self::into_scanned_files_and_directories instead.

source

pub fn directories(&self) -> &[PathBuf]

Returns a slice of all scanned directories (paths are absolute).

source

pub fn into_directories(self) -> Vec<PathBuf>

Consumes self and returns a Vec containing all scanned directories (paths are absolute).

If you are also interested in files, look at Self::files + Self::directories or Self::into_scanned_files_and_directories instead.

source

pub fn into_scanned_files_and_directories(self) -> ScannedFilesAndDirectories

Consumes self and returns a small struct containing two fields: files and directories.

Use this method when you wish to consume the scanner and are interested in both scanned files and directories. Alternatives that don’t consume the scanner are Self::files and Self::directories.

source

pub fn total_size_in_bytes(&self) -> Result<u64, DirectorySizeScanError>

Returns the total size in bytes of all scanned files and directories.

§Potential file system race conditions

Careful: this method iterates over the scanned files and directories and queries their size at call time. This means the caller will get an up-to-date directory size if they happen to call the method multiple times, potentially after modifying the one of the scanned files.

However, it also means that it this method can return, among other things, an Err(DirectorySizeScanError::ScanEntryNoLongerExists) if any file or directory that was scanned at initialization has been removed since. The same applies for files changing their read permissions, with that usually resulting in Err(DirectorySizeScanError::UnableToAccessFile).

This is very much the same thing as the relatively well-known file system race condition inherent in if file_exists(): then open_file() (time-of-check, time-of-use), just on a bigger scale.

The impact of this is—in most cases—relatively low, but it is worth noting.

§Impacts of scan depth limits

Careful: if you initialized DirectoryScan with a scan depth limit that is smaller than the actual depth of the directory tree you’re scanning, the value returned by this function will be smaller than the “real” contents of that directory.

It is up to the user to decide whether that is desired behavior or not. To find out whether the returned number of bytes will not reflect the full depth of the directory structure, see Self::covers_entire_directory_tree.

source

pub fn covers_entire_directory_tree(&self) -> bool

Returns a bool indicating whether this scan covered the entire directory tree.

For example, this can be false when the user limits the scan depth to e.g. DirectoryScanDepthLimit::Limited{ maximum_depth: 1 }, but the actual directory structure has e.g. three layers of subdirectories and files.

If maximum_scan_depth is set to DirectoryScanDepthLimit::Unlimited in the constructor for this scan, this method will always return true.

Trait Implementations§

source§

impl Clone for DirectoryScan

source§

fn clone(&self) -> DirectoryScan

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for DirectoryScan

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl PartialEq for DirectoryScan

source§

fn eq(&self, other: &DirectoryScan) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for DirectoryScan

source§

impl StructuralPartialEq for DirectoryScan

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.