reifydb_core/interface/catalog/
namespace.rs1use crate::interface::catalog::id::NamespaceId;
5
6impl NamespaceId {
7 pub const ROOT: NamespaceId = NamespaceId(0);
10}
11
12#[derive(Debug, Clone, PartialEq)]
13pub enum Namespace {
14 Local {
15 id: NamespaceId,
16 name: String,
17 local_name: String,
18 parent_id: NamespaceId,
19 },
20 Remote {
21 id: NamespaceId,
22 name: String,
23 local_name: String,
24 parent_id: NamespaceId,
25 address: String,
26 },
27}
28
29impl Namespace {
30 pub fn id(&self) -> NamespaceId {
31 match self {
32 Namespace::Local {
33 id,
34 ..
35 }
36 | Namespace::Remote {
37 id,
38 ..
39 } => *id,
40 }
41 }
42
43 pub fn name(&self) -> &str {
44 match self {
45 Namespace::Local {
46 name,
47 ..
48 }
49 | Namespace::Remote {
50 name,
51 ..
52 } => name,
53 }
54 }
55
56 pub fn local_name(&self) -> &str {
57 match self {
58 Namespace::Local {
59 local_name,
60 ..
61 }
62 | Namespace::Remote {
63 local_name,
64 ..
65 } => local_name,
66 }
67 }
68
69 pub fn parent_id(&self) -> NamespaceId {
70 match self {
71 Namespace::Local {
72 parent_id,
73 ..
74 }
75 | Namespace::Remote {
76 parent_id,
77 ..
78 } => *parent_id,
79 }
80 }
81
82 pub fn address(&self) -> Option<&str> {
83 match self {
84 Namespace::Remote {
85 address,
86 ..
87 } => Some(address),
88 _ => None,
89 }
90 }
91
92 pub fn is_remote(&self) -> bool {
93 matches!(self, Namespace::Remote { .. })
94 }
95
96 pub fn system() -> Self {
97 Self::Local {
98 id: NamespaceId(1),
99 name: "system".to_string(),
100 local_name: "system".to_string(),
101 parent_id: NamespaceId::ROOT,
102 }
103 }
104
105 pub fn default_namespace() -> Self {
106 Self::Local {
107 id: NamespaceId(2),
108 name: "default".to_string(),
109 local_name: "default".to_string(),
110 parent_id: NamespaceId::ROOT,
111 }
112 }
113}