Skip to main content

imferno_core/diagnostics/
codes.rs

1//! Shared validation-code infrastructure.
2//!
3//! This module defines the [`ValidationCode`] trait that every per-spec enum implements.
4//!
5//! Codes live in their spec's module:
6//! - [`crate::assetmap::volindex_codes`] — SMPTE ST 429-9 (VOLINDEX)
7//! - [`crate::assetmap::codes`]          — SMPTE ST 2067-2 (AssetMap / PKL)
8//! - [`crate::cpl::codes`]               — SMPTE ST 2067-3 (CPL)
9//! - [`crate::validation::codes`]        — SMPTE ST 2067-21 (App2E)
10//! - [`crate::mxf::codes`]               — SMPTE ST 377-1 (MXF)
11
12use super::{Category, Severity};
13
14// ─────────────────────────────────────────────────────────────────────────────
15// ValidationCode trait
16// ─────────────────────────────────────────────────────────────────────────────
17
18/// Metadata for a typed validation code.
19///
20/// Implement this trait on a per-spec enum to get a typed, iterable catalogue
21/// of all codes a spec emits, each with a canonical code string, description,
22/// default severity, and category.
23pub trait ValidationCode {
24    /// The canonical string written into [`crate::ValidationIssue::code`].
25    fn code(&self) -> &'static str;
26    /// A concise English description of what the constraint checks.
27    fn description(&self) -> &'static str;
28    /// The severity level assigned by the validator by default.
29    fn default_severity(&self) -> Severity;
30    /// The category bucket this code belongs to.
31    fn category(&self) -> Category;
32
33    /// One-line snippet illustrating what a violation looks like in
34    /// the source artefact. Defaults to `None`; per-code
35    /// implementations override.
36    ///
37    /// Authoring guidance: prefer a minimal XML / value fragment over
38    /// prose, so operators can scan and recognize the pattern.
39    fn example(&self) -> Option<&'static str> {
40        None
41    }
42
43    /// Prefix of the prior spec edition whose code set is bit-for-bit
44    /// identical to this one — e.g. `"ST2067-3:2013"` for
45    /// `St2067_3_2016` (the canonical 2016 XSD body is unchanged from
46    /// 2013). Used by `listRules` and downstream UIs to group / hide
47    /// duplicate cross-edition catalogues without re-diffing on the
48    /// consumer side.
49    ///
50    /// Defaults to `None`; per-enum implementations override when the
51    /// edition is confirmed identical to its predecessor (verified by
52    /// the snapshot diff documented in `docs/catalogue-todos.md`
53    /// Item 2).
54    fn previous_identical_edition(&self) -> Option<&'static str> {
55        None
56    }
57}