Skip to main content

sim_lib_namespace/
claims.rs

1//! Organ identity and operation claims for the namespace organ.
2//!
3//! The kernel owns the claim/fact store and the `OpKey` and organ-claim
4//! contracts; this module names the namespace organ and the operation keys it
5//! exposes, then publishes them as standard organ claims so the organ is
6//! discoverable through the kernel's Card surface. See the crate
7//! [`README`](https://docs.rs/sim-runtime) for the constellation framing.
8
9use sim_kernel::{
10    Cx, LibId, OpKey, Result, Symbol,
11    standard::{publish_organ_claims, publish_organ_claims_for_lib},
12};
13
14/// The symbol that identifies the namespace organ in the claim store.
15pub fn namespace_organ_symbol() -> Symbol {
16    Symbol::qualified("organ", "namespace")
17}
18
19/// Operation key for declaring a package namespace.
20pub fn namespace_package_op_key() -> OpKey {
21    namespace_op_key("package")
22}
23
24/// Operation key for declaring a module namespace.
25pub fn namespace_module_op_key() -> OpKey {
26    namespace_op_key("module")
27}
28
29/// Operation key for exporting a binding from a namespace.
30pub fn namespace_export_op_key() -> OpKey {
31    namespace_op_key("export")
32}
33
34/// Operation key for importing an exported binding into a namespace.
35pub fn namespace_import_op_key() -> OpKey {
36    namespace_op_key("import")
37}
38
39/// Operation key for importing a binding under a renamed alias.
40pub fn namespace_rename_op_key() -> OpKey {
41    namespace_op_key("rename")
42}
43
44/// Operation key for importing a binding that shadows an existing one.
45pub fn namespace_shadow_op_key() -> OpKey {
46    namespace_op_key("shadow")
47}
48
49/// The full set of operation keys exposed by the namespace organ.
50///
51/// Ordered package, module, export, import, rename, shadow; published verbatim
52/// by [`publish_namespace_organ_claims`].
53pub fn namespace_op_keys() -> Vec<OpKey> {
54    [
55        namespace_package_op_key(),
56        namespace_module_op_key(),
57        namespace_export_op_key(),
58        namespace_import_op_key(),
59        namespace_rename_op_key(),
60        namespace_shadow_op_key(),
61    ]
62    .into()
63}
64
65/// Publish the namespace organ and its operation keys as standard organ claims.
66///
67/// Realizes the kernel's organ-claim contract for the namespace organ: after
68/// this call the organ is discoverable through the kernel Card surface keyed by
69/// [`namespace_organ_symbol`].
70pub fn publish_namespace_organ_claims(cx: &mut Cx) -> Result<()> {
71    publish_organ_claims(cx, namespace_organ_symbol(), namespace_op_keys())
72}
73
74/// Publish the namespace organ claims as part of a loaded lib receipt.
75pub fn publish_namespace_organ_claims_for_lib(cx: &mut Cx, lib_id: LibId) -> Result<()> {
76    publish_organ_claims_for_lib(cx, lib_id, namespace_organ_symbol(), namespace_op_keys())
77}
78
79fn namespace_op_key(name: &str) -> OpKey {
80    OpKey::new(Symbol::new("namespace"), Symbol::new(name), 1)
81}