Skip to main content

supercode_interchange/ontology/
residue.rs

1//! Retained residue: source fields the model does not interpret, kept
2//! verbatim and re-emitted on the diagonal. Distinct from the MEASURED loss of
3//! an export-and-reload ([`crate::FidelityResidue`]); this is what a codec keeps,
4//! that is what a measurement counts.
5
6use std::collections::BTreeMap;
7
8use schemars::JsonSchema;
9use serde::{Deserialize, Serialize};
10use serde_json::Value;
11
12/// Unmodeled source fields, keyed by the source's own field name.
13#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
14#[serde(transparent)]
15pub struct Residue(pub BTreeMap<String, Value>);
16
17impl Residue {
18    /// No retained fields.
19    pub fn is_empty(&self) -> bool {
20        self.0.is_empty()
21    }
22
23    /// Keep one source field verbatim.
24    pub fn keep(&mut self, key: impl Into<String>, value: Value) {
25        self.0.insert(key.into(), value);
26    }
27}