Skip to main content

FileFilter

Struct FileFilter 

Source
pub struct FileFilter {
    pub ignored: HashSet<String>,
    pub not_ignored: HashSet<String>,
    pub extensions: HashSet<String>,
    /* private fields */
}
Available on crate feature file-changes only.
Expand description

A structure to encapsulate file path filtering behavior.

Fields§

§ignored: HashSet<String>

A set of paths or glob patterns to be ignored.

These paths/patterns are relative to the working directory. An empty entry represents the working directory itself.

§not_ignored: HashSet<String>

A set of paths or glob patterns to be explicitly not ignored.

These paths/patterns are relative to the working directory. An empty entry represents the working directory itself.

§extensions: HashSet<String>

A set of valid file extensions.

These extensions do not include the leading dot. For example, use “txt” instead of “.txt”.

A blank extension ("") can be used to match files with no extension (eg. “.clang-format”).

Implementations§

Source§

impl FileFilter

Source

pub fn new( ignore: &[&str], extensions: &[&str], log_scope: Option<&str>, ) -> Self

Construct a FileFilter instance.

The ignore parameter is a list of paths (or glob patterns). These paths/patterns get split into 2 sets: Self::ignored and Self::not_ignored. A path/pattern is explicitly not ignored if it is prefixed with !. Otherwise it is ignored.

Leading and trailing spaces are stripped from each item in the ignore list. Also, leading ./ sequences are stripped.

#[cfg(feature = "file-changes")]
use git_bot_feedback::FileFilter;
let ignore_list = [" src ", " ! src/lib.rs "];
let extensions = ["rs", "toml"];
let filter = FileFilter::new(
    &ignore_list,
    &extensions,
    None, // optional log scope for debug messages
);
assert!(filter.ignored.contains("src"));
assert!(filter.not_ignored.contains("src/lib.rs"));

Note, the log_scope parameter is used to differentiate debug log messages from different FileFilter instances.

Source

pub fn parse_submodules(&mut self, manifest_path: Option<&Path>)

This function will read a .gitmodules file located in the working directory.

The named submodules’ paths will be automatically added to the FileFilter::ignored set, unless the submodule’s path is already specified in the FileFilter::not_ignored set.

The optional manifest_path parameter can be used to specify a custom path to the .gitmodules file. If None, a .gitmodules file in the working directory is sought.

It is important that the Self::ignored and Self::not_ignored should be relative to the manifest_path’s parent directory, because the paths in the .gitmodules file are relative to it’s own directory.

Source

pub fn is_file_in_list(&self, file_name: &Path, is_ignored: bool) -> bool

Describes if a specified file_name is contained within the specified set of paths.

The is_ignored flag describes which set of paths is used as domains. The specified file_name can be a direct or distant descendant of any paths in the set.

Returns a true value of the the path/pattern that matches the given file_name. If given file_name is not in the specified set, then false is returned.

Source

pub fn is_file_ignored(&self, file_name: &Path) -> bool

Convenience function to check if a given file_name is ignored.

Equivalent to calling file_filter.is_file_in_list(file_name, true).

Source

pub fn is_file_not_ignored(&self, file_name: &Path) -> bool

Convenience function to check if a given file_name is not ignored.

Equivalent to calling file_filter.is_file_in_list(file_name, false).

Source

pub fn is_qualified(&self, file_path: &Path) -> bool

A function that checks if file_path satisfies the following conditions (in ordered priority):

Note, the given file_path should be relative to the same directory that the paths in FileFilter::ignored and FileFilter::not_ignored are relative to.

Source

pub fn walk_dir<P: AsRef<Path>>( &self, root_path: P, ) -> Result<HashSet<String>, DirWalkError>

Walks a given root_path recursively and returns a set of discovered source files.

Only files that satisfy the following conditions are included in the returned set:

The file paths returned (as strings with posix style path separators) will be relative to the given path.

Trait Implementations§

Source§

impl Clone for FileFilter

Source§

fn clone(&self) -> FileFilter

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for FileFilter

Source§

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

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

impl Default for FileFilter

Source§

fn default() -> FileFilter

Returns the “default value” for a type. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

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

Source§

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>,

Source§

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>,

Source§

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more