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 {
55 let namespace = namespace.into();
56 let id = root_node_id(&namespace);
57 Self::new(
58 framework,
59 namespace,
60 "root",
61 id,
62 RegistrationRule::ANY.into_owned(),
63 "<registry-root>",
64 Admission::ANY.into_owned(),
65 )
66 }
67
68 #[allow(clippy::too_many_arguments)]
69 pub(super) fn new(
70 framework: FrameworkId,
71 namespace: String,
72 path: &str,
73 id: NodeId,
74 registration_rule: OwnedRegistrationRule,
75 registration_rule_path: impl Into<String>,
76 admission: OwnedAdmission,
77 ) -> Self {
78 Self {
79 header: Arc::new(RegistryHeader {
80 namespace,
81 framework,
82 path: path.to_owned(),
83 id,
84 registration_rule,
85 registration_rule_path: registration_rule_path.into(),
86 admission,
87 }),
88 entries: Arc::new(EntryPages::default()),
89 }
90 }
91
92 pub fn framework(&self) -> FrameworkId {
95 self.header.framework
96 }
97}