supercode-interchange 0.4.17

Canonical, provider-neutral session interchange primitives for Supercode
Documentation
//! Retained residue: source fields the model does not interpret, kept
//! verbatim and re-emitted on the diagonal. Distinct from the MEASURED loss of
//! an export-and-reload ([`crate::FidelityResidue`]); this is what a codec keeps,
//! that is what a measurement counts.

use std::collections::BTreeMap;

use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_json::Value;

/// Unmodeled source fields, keyed by the source's own field name.
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(transparent)]
pub struct Residue(pub BTreeMap<String, Value>);

impl Residue {
    /// No retained fields.
    pub fn is_empty(&self) -> bool {
        self.0.is_empty()
    }

    /// Keep one source field verbatim.
    pub fn keep(&mut self, key: impl Into<String>, value: Value) {
        self.0.insert(key.into(), value);
    }
}