Skip to main content

helm_schema_core/
provenance.rs

1use serde::{Deserialize, Serialize};
2
3/// Byte span within a template source file.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
5pub struct SourceSpan {
6    /// Inclusive byte offset where the source range begins.
7    pub start: usize,
8    /// Exclusive byte offset where the source range ends.
9    pub end: usize,
10}
11
12impl SourceSpan {
13    /// Creates a half-open source range.
14    #[must_use]
15    pub fn new(start: usize, end: usize) -> Self {
16        Self { start, end }
17    }
18}
19
20/// Source provenance for one emitted contract fact.
21#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
22pub struct ContractProvenance {
23    /// Chart-relative template file containing the evidence.
24    pub template_path: String,
25    /// Byte range of the expression that produced the evidence.
26    pub span: SourceSpan,
27    /// Named helpers traversed from the template to the expression.
28    #[serde(default, skip_serializing_if = "Vec::is_empty")]
29    pub helper_chain: Vec<String>,
30}
31
32impl ContractProvenance {
33    /// Creates provenance for one expression and its helper call chain.
34    #[must_use]
35    pub fn new(
36        template_path: impl Into<String>,
37        span: SourceSpan,
38        helper_chain: Vec<String>,
39    ) -> Self {
40        Self {
41            template_path: template_path.into(),
42            span,
43            helper_chain,
44        }
45    }
46}