Struct gitignore::File

source ·
pub struct File<'a> { /* private fields */ }
Expand description

Represents a .gitignore file. Use this to load the .gitignore file, parse the patterns, and then check if a given path would be excluded by any rules contained therein.

Examples

let file = gitignore::File::new(&gitignore_path).unwrap();
assert!(file.is_excluded(&path_to_test_if_excluded).unwrap())

Implementations§

source§

impl<'b> File<'b>

source

pub fn new(gitignore_path: &'b Path) -> Result<File<'b>, Error>

Parse the given .gitignore file for patterns, allowing any arbitrary path to be checked against the set of rules to test for exclusion.

The value of gitignore_path must be an absolute path.

source

pub fn is_excluded(&self, path: &'b Path) -> Result<bool, Error>

Returns true if, after checking against all the patterns found in the .gitignore file, the given path is matched any of the globs (applying negated patterns as expected). Note this function also returns false if the path does not exist.

If the value for path is not absolute, it will assumed to be relative to the current working directory.

source

pub fn included_files(&self) -> Result<Vec<PathBuf>, Error>

Returns a list of files that are not excluded by the rules in the loaded .gitignore file. It recurses through all subdirectories and returns everything that is not ignored.

Trait Implementations§

source§

impl<'a> Debug for File<'a>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for File<'a>

§

impl<'a> Send for File<'a>

§

impl<'a> Sync for File<'a>

§

impl<'a> Unpin for File<'a>

§

impl<'a> UnwindSafe for File<'a>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.