pub struct Context<'a> {
pub root: &'a Path,
pub index: &'a FileIndex,
pub registry: Option<&'a RuleRegistry>,
pub facts: Option<&'a FactValues>,
pub vars: Option<&'a HashMap<String, String>>,
pub git_tracked: Option<&'a HashSet<PathBuf>>,
pub git_blame: Option<&'a BlameCache>,
}Expand description
Execution context handed to each rule during evaluation.
registry— available for rules that need to build and evaluate nested rules at runtime (e.g.for_each_dir). Tests that don’t exercise nested evaluation can set this toNone.facts— resolved fact values, computed once perEngine::run.vars— user-supplied string variables from the config’svars:section.git_tracked— set of repo paths reported bygit ls-files, computed once per run when at least one rule hasgit_tracked_only: true.Noneoutside a git repo or when no rule asked for it. Rules that opt in consult it viaContext::is_git_tracked.git_blame— per-filegit blamecache, computed lazily when at least one rule reportswants_git_blame().Nonewhen no rule asked for it. Rules consult it viacrate::git::BlameCache::get; both “outside a git repo” and “blame failed for this file” surface as aNonelookup, which the rule treats as “silent no-op.”
Fields§
§root: &'a Path§index: &'a FileIndex§registry: Option<&'a RuleRegistry>§facts: Option<&'a FactValues>§vars: Option<&'a HashMap<String, String>>§git_tracked: Option<&'a HashSet<PathBuf>>§git_blame: Option<&'a BlameCache>Implementations§
Source§impl Context<'_>
impl Context<'_>
Sourcepub fn is_git_tracked(&self, rel_path: &Path) -> bool
pub fn is_git_tracked(&self, rel_path: &Path) -> bool
True if rel_path is in git’s index. Returns false when
no tracked-set was computed (no git repo, or no rule asked
for it). Rules that opt into git_tracked_only therefore
silently skip every entry outside a git repo, which is the
right behaviour for the canonical “don’t let X be
committed” use case.
Sourcepub fn dir_has_tracked_files(&self, rel_path: &Path) -> bool
pub fn dir_has_tracked_files(&self, rel_path: &Path) -> bool
True if the directory at rel_path contains at least one
git-tracked file. Used by dir_* rules opting into
git_tracked_only. Same None-means-untracked semantics
as Context::is_git_tracked.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Context<'a>
impl<'a> RefUnwindSafe for Context<'a>
impl<'a> Send for Context<'a>
impl<'a> Sync for Context<'a>
impl<'a> Unpin for Context<'a>
impl<'a> UnsafeUnpin for Context<'a>
impl<'a> UnwindSafe for Context<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more