nichlink/registry_core/tree/
registry.rs1use std::sync::Arc;
5
6use super::entry_pages::EntryPages;
7use super::header::RegistryHeader;
8pub use super::index::{RegistryIndex, RegistryStorageStats};
9use crate::registry_core::declaration::FrameworkId;
10use crate::registry_core::declaration::{
11 Admission, OwnedAdmission, OwnedRegistrationRule, RegistrationRule,
12};
13use crate::registry_core::identity::{NodeId, ROOT_NODE_ID, root_node_id};
14
15#[derive(Clone, Debug)]
18pub struct Registry {
19 pub(super) header: Arc<RegistryHeader>,
20 pub(super) entries: Arc<EntryPages>,
24}
25
26impl Default for Registry {
27 fn default() -> Self {
28 Self::root()
29 }
30}
31
32impl Registry {
33 pub fn root() -> Self {
36 Self::new(
37 FrameworkId::new("nichlink.default"),
38 "nichlink.default".to_owned(),
39 "root",
40 ROOT_NODE_ID,
41 RegistrationRule::ANY.into_owned(),
42 "<registry-root>",
43 Admission::ANY.into_owned(),
44 )
45 }
46
47 pub fn root_for(framework: FrameworkId) -> Self {
50 Self::root_for_namespace(framework, framework.0)
51 }
52
53 pub fn root_for_namespace(framework: FrameworkId, namespace: impl Into<String>) -> Self {
56 let namespace = namespace.into();
57 let id = root_node_id(&namespace);
58 Self::new(
59 framework,
60 namespace,
61 "root",
62 id,
63 RegistrationRule::ANY.into_owned(),
64 "<registry-root>",
65 Admission::ANY.into_owned(),
66 )
67 }
68
69 #[allow(clippy::too_many_arguments)]
70 pub(super) fn new(
71 framework: FrameworkId,
72 namespace: String,
73 path: &str,
74 id: NodeId,
75 registration_rule: OwnedRegistrationRule,
76 registration_rule_path: impl Into<String>,
77 admission: OwnedAdmission,
78 ) -> Self {
79 Self {
80 header: Arc::new(RegistryHeader {
81 namespace,
82 framework,
83 path: path.to_owned(),
84 id,
85 registration_rule,
86 registration_rule_path: registration_rule_path.into(),
87 admission,
88 }),
89 entries: Arc::new(EntryPages::default()),
90 }
91 }
92
93 pub fn framework(&self) -> FrameworkId {
96 self.header.framework
97 }
98}