Expand description
The fixed registry of shipped policies. What: The fixed registry of policies compiled into the native wrapper. Why: Repository JSONC can only tune shipped policies; it can never name code to run.
In TS you’d write (pseudocode):
// const POLICY_REGISTRY = [{ name: 'require-root', defaultSeverity: 'error', ... }] as const;Structs§
- Policy
Descriptor - What:
struct PolicyDescriptoris one registry row.&'static stris a borrowed string baked into the executable for its whole run ('staticis that “lives forever” lifetime). Sibling:String, an owned copy.boolistrue/false, exactly TSboolean. Why: Registry text is compiled in and never changes, so borrowing forever is free, whileStringwould allocate at startup for no gain.
Enums§
- Policy
Id - What: One variant per shipped policy; the variant is the policy’s identity in Rust. Why: Typed identities let options and settings be looked up without string comparison.
- Severity
- What:
enum Severityis a closed set of three named values.#[derive(...)]asks the compiler to generate copying, printing and==. Why: A closed set makes an unhandled severity a compile error, unlike a free string.
Constants§
- POLICY_
REGISTRY - What:
pub const POLICY_REGISTRY: &[PolicyDescriptor]is a compiled-in, read-only list.&[T]is a borrowed view of an array; siblings areVec<T>(owned, growable) and[T; N](fixed length in the type). Why: Execution and configuration order must be identical on every run; a borrowed constant needs no allocation and cannot be reordered at runtime. Every default is the incumbent policy definition’s owndefaultSeverity. The four formerly plugin-provided policies are additionally off unless the repository configuration names them, because the incumbent only ran them in repositories whose configuration registered their plugin.
Functions§
- policy_
by_ name - What:
Find a registry row by its configuration key.
Option<T>is Rust’s “value or nothing”:Some(row)orNone.&'static PolicyDescriptorborrows a row that lives as long as the program. Why: An unknown policy ID must be reported, never treated as a new policy. - policy_
descriptor - What:
Find the registry row for a typed identity.
Why:
Callers holding a
PolicyIdneed its name, default and warn-safety. - severity_
from_ name - What: Translate a configuration word into a typed severity. Why: Only the three documented spellings are settings; anything else is an error the caller reports with the offending key.
- severity_
name - What: Translate a typed severity back to its configuration and JSONL spelling. Why: Events and diagnostics print the same words the configuration accepts.