canic_core/ops/
wasm.rs

1use crate::{
2    Error, ids::CanisterRole, log, log::Topic, model::wasm::WasmRegistry, types::WasmModule,
3};
4
5///
6/// WasmOps
7/// Thin ops-layer wrapper around the embedded WasmRegistry.
8///
9
10pub struct WasmOps;
11
12impl WasmOps {
13    /// Fetch a WASM module for the given canister type if registered.
14    #[must_use]
15    pub fn get(role: &CanisterRole) -> Option<WasmModule> {
16        WasmRegistry::get(role)
17    }
18
19    /// Fetch a WASM module or return an error when missing.
20    pub fn try_get(role: &CanisterRole) -> Result<WasmModule, Error> {
21        WasmRegistry::try_get(role)
22    }
23
24    /// Import a static slice of (role, wasm bytes) at startup.
25    #[allow(clippy::cast_precision_loss)]
26    pub fn import_static(wasms: &'static [(CanisterRole, &[u8])]) {
27        for (role, bytes) in wasms {
28            let wasm = WasmModule::new(bytes);
29            let wasm_size = wasm.len();
30
31            WasmRegistry::insert(role, wasm);
32
33            log!(
34                Topic::Wasm,
35                Info,
36                "📄 registry.insert: {} ({:.2} KB)",
37                role,
38                wasm_size as f64 / 1000.0
39            );
40        }
41    }
42}