Skip to main content

molgfx_core/dataset/
identity.rs

1//! Stable dataset identities and checked chunk-local addressing.
2
3use core::fmt;
4
5/// Stable identity of one logical dataset.
6#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
7pub struct DatasetId(u64);
8
9impl DatasetId {
10    /// Dataset identity used by transitional constructors that receive only a
11    /// parsed structure and therefore have no caller-owned global identity.
12    pub const LEGACY: Self = Self(0);
13
14    /// Creates an identity from the caller's stable value.
15    #[must_use]
16    pub const fn new(value: u64) -> Self {
17        Self(value)
18    }
19
20    /// Returns the caller's stable value.
21    #[must_use]
22    pub const fn get(self) -> u64 {
23        self.0
24    }
25}
26
27impl fmt::Display for DatasetId {
28    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
29        self.0.fmt(formatter)
30    }
31}
32
33/// Stable identity of one chunk within a dataset.
34#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
35pub struct ChunkId(u64);
36
37impl ChunkId {
38    /// Creates an identity from the caller's stable value.
39    #[must_use]
40    pub const fn new(value: u64) -> Self {
41        Self(value)
42    }
43
44    /// Returns the caller's stable value.
45    #[must_use]
46    pub const fn get(self) -> u64 {
47        self.0
48    }
49}
50
51impl fmt::Display for ChunkId {
52    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
53        self.0.fmt(formatter)
54    }
55}
56
57/// Stable caller identity for one spatial occurrence of a resident chunk.
58///
59/// A chunk can be drawn more than once with distinct transforms or shared
60/// templates. Spatial relations therefore address an occurrence as well as a
61/// dataset, chunk and logical row.
62#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
63pub struct ChunkOccurrenceId(u64);
64
65impl ChunkOccurrenceId {
66    /// Creates a stable caller-owned occurrence identity.
67    #[must_use]
68    pub const fn new(value: u64) -> Self {
69        Self(value)
70    }
71
72    /// Returns the underlying stable value.
73    #[must_use]
74    pub const fn get(self) -> u64 {
75        self.0
76    }
77}
78
79impl fmt::Display for ChunkOccurrenceId {
80    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
81        self.0.fmt(formatter)
82    }
83}
84
85/// Stable row identity in the full logical dataset.
86#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
87pub struct LogicalRow(u64);
88
89impl LogicalRow {
90    /// Creates a logical row from the caller's stable value.
91    #[must_use]
92    pub const fn new(value: u64) -> Self {
93        Self(value)
94    }
95
96    /// Returns the full-dataset row value.
97    #[must_use]
98    pub const fn get(self) -> u64 {
99        self.0
100    }
101}
102
103impl fmt::Display for LogicalRow {
104    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
105        self.0.fmt(formatter)
106    }
107}
108
109/// Dense row index valid only inside one resident chunk.
110#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
111pub struct LocalRow(u32);
112
113impl LocalRow {
114    /// Creates a chunk-local row.
115    #[must_use]
116    pub const fn new(value: u32) -> Self {
117        Self(value)
118    }
119
120    /// Returns the local GPU-compatible index.
121    #[must_use]
122    pub const fn get(self) -> u32 {
123        self.0
124    }
125}
126
127#[cfg(test)]
128#[path = "identity_tests.rs"]
129mod tests;