#[non_exhaustive]pub struct Violation {
pub kind: BoundaryKind,
pub target: String,
pub rule: String,
pub finding: String,
pub reason: String,
pub severity: Severity,
pub baselined: bool,
pub file: Option<String>,
pub anchor: Option<String>,
pub polarity: Option<Polarity>,
}Expand description
One violated boundary. severity is the producing boundary’s severity, so the
exit-code decision and the report can treat enforce and warn findings apart.
baselined is set when baseline gating records the violation in a baseline; a
baselined violation does not fail the reaction.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.kind: BoundaryKindWhich kind of boundary produced this violation.
target: StringThe governed target (crate name, or module path for a module boundary).
rule: StringThe rule label that was violated.
finding: StringThe offending finding (e.g. the dependency name, or the imported module path).
reason: StringThe boundary’s reason — the repair hint.
severity: SeverityThe producing boundary’s severity.
baselined: boolWhether this violation is recorded in the active baseline (so it does not fail).
file: Option<String>The offending source file, when the producing dimension genuinely observes one — a
faithful byproduct of the scan (e.g. the file a forbidden import sits in). None when
the violation has no single source file (a dependency edge, a seam name) or the
dimension does not yet observe a per-element file. Set via Violation::with_file, not
the constructor, so adding it leaves Violation::new non-breaking; it is not part
of the baseline identity (Violation::id), so it never affects baseline matching.
anchor: Option<String>The producing boundary’s durable governance anchor — a stable pointer (e.g. "ADR-014")
into the project’s governance, distinct from the free-text reason sentence, which accretes
ephemeral refs (PR numbers, handles, “recently”) that rot faster than the invariant they
justify. None when the boundary declared none. Set via Violation::with_anchor, not the
constructor, so adding it leaves Violation::new non-breaking; like file, it is metadata,
not part of the baseline identity (Violation::id), so it never affects baseline
matching, and it is never a reaction input — a pure durable pointer.
polarity: Option<Polarity>The repair direction of a boundary-drift violation (Polarity) — DenyBreach (remove
the offending code) or AllowlistGap (remove, or declare the intent). Derived from the
producing rule’s type at the reaction site, set via Violation::with_polarity, not the
constructor. None for a violation off the boundary-drift axis (the runtime CI-audit
coverage violations), whose repair is read from the reason/finding. Like file/anchor,
it is metadata: not part of the baseline identity (Violation::id) — being a pure
function of the rule it is constant for a given identity anyway — and never a reaction input.
Implementations§
Source§impl Violation
impl Violation
Sourcepub fn new(
kind: BoundaryKind,
target: String,
rule: String,
finding: String,
reason: String,
severity: Severity,
) -> Violation
pub fn new( kind: BoundaryKind, target: String, rule: String, finding: String, reason: String, severity: Severity, ) -> Violation
Build a violation an engine has just observed: baselined starts false and is
set later by apply_baseline. The constructor a dimension crate needs because
Violation is #[non_exhaustive] and cannot be struct-literal-built across the
crate boundary.
Sourcepub fn with_file(self, file: Option<String>) -> Violation
pub fn with_file(self, file: Option<String>) -> Violation
Attach the offending source file, consuming and returning self so a dimension can
fold it into construction: Violation::new(…).with_file(Some(path)). Kept off
Violation::new on purpose — the constructor’s signature stays stable (non-breaking)
and dimensions that observe no file simply never call this. The file is metadata, never
part of the baseline identity (Violation::id).
Sourcepub fn with_anchor(self, anchor: Option<String>) -> Violation
pub fn with_anchor(self, anchor: Option<String>) -> Violation
Attach the producing boundary’s durable governance anchor, consuming and returning self
so a dimension can fold it into construction: Violation::new(…).with_anchor(boundary…).
Kept off Violation::new on purpose — the constructor’s signature stays stable
(non-breaking), and a boundary that declared no anchor simply never calls this (or passes
None). The anchor is metadata, never part of the baseline identity (Violation::id).
Sourcepub fn with_polarity(self, polarity: Polarity) -> Violation
pub fn with_polarity(self, polarity: Polarity) -> Violation
Stamp the violation’s repair-direction Polarity, consuming and returning self so a
dimension can fold it into construction: Violation::new(…).with_polarity(rule.polarity()).
Takes a concrete Polarity (not an Option) because a reaction site that stamps one always
knows it; a violation off the boundary-drift axis simply never calls this, leaving None.
The polarity is metadata, never part of the baseline identity (Violation::id).
Sourcepub fn id(&self) -> ViolationId
pub fn id(&self) -> ViolationId
The (target, rule, finding) identity used to match against a baseline.