pub trait PerFileRule:
Send
+ Sync
+ Debug {
// Required methods
fn path_scope(&self) -> &Scope;
fn evaluate_file(
&self,
ctx: &Context<'_>,
path: &Path,
bytes: &[u8],
) -> Result<Vec<Violation>>;
// Provided method
fn max_bytes_needed(&self) -> Option<usize> { ... }
}Expand description
File-major dispatch entry-point for a per-file rule.
Rules that can evaluate one file at a time given a pre-loaded
byte slice implement this trait alongside Rule and opt
into the file-major path via Rule::as_per_file. The
engine reads each file once per evaluation pass and calls
evaluate_file on every per-file rule whose
path_scope matches that file —
avoiding the per-rule std::fs::read the rule-major loop
would otherwise duplicate.
Implementations MUST NOT call std::fs::read themselves; the
bytes argument is the engine’s already-read content. The
rule’s existing Rule::evaluate implementation (which does
read the file) stays in place as the rule-major fallback —
it’s still the path used by alint fix (sequential
filesystem mutation rules out coalesced reads there) and by
fallback test harnesses.
Required Methods§
Sourcefn path_scope(&self) -> &Scope
fn path_scope(&self) -> &Scope
The rule’s scope. The engine checks
path_scope().matches(path) before calling
evaluate_file; a rule that returns
Scope::match_all is
in scope for every file.
Sourcefn evaluate_file(
&self,
ctx: &Context<'_>,
path: &Path,
bytes: &[u8],
) -> Result<Vec<Violation>>
fn evaluate_file( &self, ctx: &Context<'_>, path: &Path, bytes: &[u8], ) -> Result<Vec<Violation>>
Evaluate one file given the engine’s already-read byte
content. The path is the relative path from the lint
root; the rule should with_path(path.into()) (or clone
the matched FileEntry::path
if it has one in hand) on emitted violations.
Provided Methods§
Sourcefn max_bytes_needed(&self) -> Option<usize>
fn max_bytes_needed(&self) -> Option<usize>
Optional lower bound on the bytes the rule needs to
evaluate. Default None means “I need the whole file.”
Used as a hint; the engine in v0.9.3 reads the whole
file regardless and hands it to every applicable rule —
the hint is reserved for a future engine-side bounded-
read optimisation.