Skip to main content

sim_lib_mutation/
claims.rs

1use sim_kernel::{
2    Cx, LibId, OpKey, Result, Symbol,
3    standard::{publish_organ_claims, publish_organ_claims_for_lib},
4};
5
6/// The organ symbol under which this crate publishes its claims: `organ:mutation`.
7pub fn mutation_organ_symbol() -> Symbol {
8    Symbol::qualified("organ", "mutation")
9}
10
11/// Operation key for constructing a mutable cell (`mutation/cell`).
12pub fn mutation_cell_op_key() -> OpKey {
13    mutation_op_key("cell")
14}
15
16/// Operation key for constructing a mutable box (`mutation/box`).
17pub fn mutation_box_op_key() -> OpKey {
18    mutation_op_key("box")
19}
20
21/// Operation key for an in-place write (`mutation/set`).
22pub fn mutation_set_op_key() -> OpKey {
23    mutation_op_key("set")
24}
25
26/// Operation key for constructing a mutable vector (`mutation/vector`).
27pub fn mutation_vector_op_key() -> OpKey {
28    mutation_op_key("vector")
29}
30
31/// Operation key for constructing a mutable table (`mutation/table`).
32pub fn mutation_table_op_key() -> OpKey {
33    mutation_op_key("table")
34}
35
36/// The full set of mutation operation keys this organ exposes.
37///
38/// Ordered cell, box, set, vector, table; passed to
39/// [`publish_mutation_organ_claims`] when the organ registers its claims.
40pub fn mutation_op_keys() -> Vec<OpKey> {
41    [
42        mutation_cell_op_key(),
43        mutation_box_op_key(),
44        mutation_set_op_key(),
45        mutation_vector_op_key(),
46        mutation_table_op_key(),
47    ]
48    .into()
49}
50
51/// Publish the mutation organ and its operation keys as claims into `cx`.
52///
53/// Registers [`mutation_organ_symbol`] as a standard organ carrying
54/// [`mutation_op_keys`], making the organ discoverable through the kernel card
55/// and claim surfaces.
56pub fn publish_mutation_organ_claims(cx: &mut Cx) -> Result<()> {
57    publish_organ_claims(cx, mutation_organ_symbol(), mutation_op_keys())
58}
59
60/// Publish the mutation organ claims as part of a loaded lib receipt.
61pub fn publish_mutation_organ_claims_for_lib(cx: &mut Cx, lib_id: LibId) -> Result<()> {
62    publish_organ_claims_for_lib(cx, lib_id, mutation_organ_symbol(), mutation_op_keys())
63}
64
65fn mutation_op_key(name: &str) -> OpKey {
66    OpKey::new(Symbol::new("mutation"), Symbol::new(name), 1)
67}