Skip to main content

improv_core_model/
ids.rs

1//! Opaque, stable identifiers and human-readable names.
2
3use serde::{Deserialize, Serialize};
4
5macro_rules! id_type {
6    ($(#[$m:meta])* $name:ident) => {
7        $(#[$m])*
8        #[derive(
9            Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize,
10        )]
11        pub struct $name(pub u32);
12    };
13}
14
15id_type!(
16    /// Identifies a category (a model dimension).
17    CategoryId
18);
19id_type!(
20    /// Identifies an item (a member of a category).
21    ItemId
22);
23id_type!(
24    /// Identifies a measure (an input or derived variable).
25    MeasureId
26);
27id_type!(
28    /// Identifies a saved view (pivot/grid layout).
29    ViewId
30);
31id_type!(
32    /// Identifies a what-if scenario (an input-override overlay).
33    ScenarioId
34);
35
36/// A human-readable name. Unique within its scope; renamable without breaking
37/// formulas (formulas bind to ids, not names).
38#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
39pub struct Name(pub String);
40
41impl From<&str> for Name {
42    fn from(s: &str) -> Self {
43        Name(s.to_string())
44    }
45}
46
47impl std::fmt::Display for Name {
48    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
49        f.write_str(&self.0)
50    }
51}