Skip to main content

backhopper_core/model/
schema_files.rs

1// Copyright (C) 2026 Michael S. Klishin and Contributors
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3// See LICENSE-APACHE and LICENSE-MIT for details.
4
5//! The Cuttlefish files an app ships under `priv/schema/`.
6
7use std::collections::BTreeSet;
8use std::fmt;
9
10use serde::{Deserialize, Serialize};
11
12use crate::model::names::{ApplicationName, ConfKey, PartialName, RelativePath, ValidatorName};
13
14/// A `*.schema` file: the keys it maps and the validators it defines.
15#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
16pub struct SchemaFile {
17    pub path: RelativePath,
18    pub app: ApplicationName,
19    pub mappings: BTreeSet<ConfKey>,
20    pub validators: BTreeSet<ValidatorName>,
21}
22
23/// A `*.partial` file. Its mappings are bare keys, before the including
24/// schema's prefix is applied: the names `exclude` and `overrides` use.
25#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
26pub struct PartialFile {
27    pub path: RelativePath,
28    pub app: ApplicationName,
29    pub name: PartialName,
30    pub mappings: BTreeSet<ConfKey>,
31    pub validators: BTreeSet<ValidatorName>,
32}
33
34/// How `{include_partial, {App, Name}, ...}` addresses a partial.
35#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
36pub struct PartialRef {
37    pub app: ApplicationName,
38    pub name: PartialName,
39}
40
41impl PartialFile {
42    #[must_use]
43    pub fn partial_ref(&self) -> PartialRef {
44        PartialRef {
45            app: self.app.clone(),
46            name: self.name.clone(),
47        }
48    }
49}
50
51impl fmt::Display for PartialRef {
52    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
53        write!(f, "{{{}, \"{}\"}}", self.app, self.name)
54    }
55}