Skip to main content

nodedb_array/types/
array_id.rs

1// SPDX-License-Identifier: Apache-2.0
2
3//! Stable array identifier — tenant-scoped logical name.
4
5use serde::{Deserialize, Serialize};
6
7use nodedb_types::TenantId;
8
9/// Logical handle to an array within a tenant. The pair
10/// `(tenant_id, name)` is the canonical key used by storage and the
11/// catalog; `name` is the user-visible identifier.
12#[derive(
13    Debug,
14    Clone,
15    PartialEq,
16    Eq,
17    Hash,
18    Serialize,
19    Deserialize,
20    zerompk::ToMessagePack,
21    zerompk::FromMessagePack,
22)]
23pub struct ArrayId {
24    pub tenant_id: TenantId,
25    pub name: String,
26}
27
28impl ArrayId {
29    pub fn new(tenant_id: TenantId, name: impl Into<String>) -> Self {
30        Self {
31            tenant_id,
32            name: name.into(),
33        }
34    }
35}
36
37#[cfg(test)]
38mod tests {
39    use super::*;
40
41    #[test]
42    fn array_id_round_trip_eq() {
43        let a = ArrayId::new(TenantId::new(1), "genome");
44        let b = ArrayId::new(TenantId::new(1), "genome");
45        assert_eq!(a, b);
46    }
47}