Struct gitignore::Pattern

source ·
pub struct Pattern<'c> {
    pub pattern: Pattern,
    pub anchored: bool,
    pub negation: bool,
    /* private fields */
}
Expand description

A pattern as found in a .gitignore file.

Fields§

§pattern: Pattern

The glob pattern after being parsed, negation or trailing directory slashes removed, and the root prepended if anchored.

§anchored: bool

Whether the pattern had the root prepended so the matches must be within the root directory. That is to say, whether the pattern was anchored to the root.

§negation: bool

Whether the pattern should, if it matches, negate any previously matching patterns. This flag has no effect if no previous patterns had matched.

Implementations§

source§

impl<'c> Pattern<'c>

source

pub fn new(raw_pattern: &str, root: &'c Path) -> Result<Pattern<'c>, Error>

Create a new pattern from the raw glob as found in a .gitignore file.

The value of root must be an absolute path.

source

pub fn is_excluded(&self, path: &Path, directory: bool) -> bool

Returns true if the given path is matched by the current pattern, and hence would be excluded if found in a .gitignore file. The second argument, directory, is a bool representing whether the given path is a directory - if so, it should be set to true, otherwise false if not (eg. file, special file, symlink).

Note that if the glob was negated (ie. of the format ! some/glob/*.here) then this will return the opposite value, eg. false if the pattern matched, and true if the pattern did not match.

The value of path must be an absolute path.

Trait Implementations§

source§

impl<'c> Debug for Pattern<'c>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'c> RefUnwindSafe for Pattern<'c>

§

impl<'c> Send for Pattern<'c>

§

impl<'c> Sync for Pattern<'c>

§

impl<'c> Unpin for Pattern<'c>

§

impl<'c> UnwindSafe for Pattern<'c>

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.